# 概率dp

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors
and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and
if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit
this island after a long enough period of time.

Input

The single line contains three integers rs and p (1 ≤ r, s, p ≤ 100) —
the original number of individuals in the species of rock, scissors and paper, respectively.

Output

Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn’t exceed 10 - 9.

Sample test(s)
input
```2 2 2
```
output
```0.333333333333 0.333333333333 0.333333333333
```
input
```2 1 2
```
output
```0.150000000000 0.300000000000 0.550000000000
```
input
```1 1 3
```
output
```0.057142857143 0.657142857143 0.285714285714
```

code：

``````#include<bits/stdc  .h>
using namespace std;
typedef long long ll;
#define INF 1<<30
double dp[110][110][110];
double R, S, P;
int main()
{
int r, s, p;
cin >> r >> s >> p;
dp[r][s][p] = 1.0;
for(int i=r; i>=0; i--)
{
for(int j=s; j>=0; j--)
{
for(int k=p; k>=0; k--)
{
double sum = i*j i*k j*k;
if(i && sum) dp[i-1][j][k]  = (i*k)/sum*dp[i][j][k];
if(j && sum) dp[i][j-1][k]  = (i*j)/sum*dp[i][j][k];
if(k && sum) dp[i][j][k-1]  = (j*k)/sum*dp[i][j][k];
}
}
}
for(int i=0; i<=r; i  )
R  = dp[i][0][0];
for(int i=0; i<=s; i  )
S  = dp[0][i][0];
for(int i=0; i<=p; i  )
P  = dp[0][0][i];
printf("%.9f %.9f %.9f\n", R,S,P);
return 0;
}``````

``````#include<stdio.h>
double dp[110][110][110];
double dfs(int r, int s, int p)
{
if(dp[r][s][p]) return dp[r][s][p];
if(p == 0) return 1; //當p==0也就是說，當p滅絕，此時最終留下來的是物種r
if(s*r == 0) return 0; //表示物種r或s滅絕的概率為0，因為我已假設就是p物種滅絕
//一直算到有一種物種滅絕，這樣就可以直接知道誰存活，是不是滿足自己的假設
int sum = r*s r*p s*p;
return dp[r][s][p] = 1.0*r*s/sum*dfs(r,s-1,p) 1.0*r*p/sum*dfs(r-1,s,p) 1.0*s*p/sum*dfs(r,s,p-1);
}
int main()
{
int r, s, p;
scanf("%d%d%d", &r,&s,&p);
printf("%.9f %.9f %.9f\n", dfs(r,s,p),dfs(s,p,r),dfs(p,r,s));
//dfs(i,j,k)表示i存活，算到k滅絕為止
return 0;
}``````