Advertisement
Guest User

Untitled

a guest
Apr 30th, 2015
4,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <string>
  7. using namespace std;
  8.  
  9. typedef long double ld;
  10.  
  11. ld a[105][105][105];
  12.  
  13. int main() {
  14.     int R, S, P;
  15.     cin >> R >> S >> P;
  16.  
  17.     a[R][S][P] = 1;
  18.     for (int sum = R + S + P; sum > 0; sum--) {
  19.         for (int r = R; r >= 0; r--) {
  20.             for (int s = S; s >= 0; s--) {
  21.                 int p = sum - r - s;
  22.                 if (p < 0 || p > P) continue;
  23.                 if (r == 0 && s == 0) continue;
  24.                 if (r == 0 && p == 0) continue;
  25.                 if (s == 0 && p == 0) continue;
  26.                 ld cur = a[r][s][p];
  27.                 int waysR = r * s;
  28.                 int waysS = s * p;
  29.                 int waysP = p * r;
  30.                 int totalWays = waysR + waysS + waysP;
  31.                 if (r > 0) a[r - 1][s][p] += cur * waysP / totalWays;
  32.                 if (s > 0) a[r][s - 1][p] += cur * waysR / totalWays;
  33.                 if (p > 0) a[r][s][p - 1] += cur * waysS / totalWays;
  34.             }
  35.         }
  36.     }
  37.  
  38.     ld ansR = 0;
  39.     ld ansS = 0;
  40.     ld ansP = 0;
  41.     for (int r = 1; r <= R; r++) ansR += a[r][0][0];
  42.     for (int s = 1; s <= S; s++) ansS += a[0][s][0];
  43.     for (int p = 1; p <= P; p++) ansP += a[0][0][p];
  44.  
  45.     printf("%.12f %.12f %.12f\n", (double)ansR, (double)ansS, (double)ansP);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement