Discription
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp 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 r, s 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.
Example
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 方程的转移比较显然23333,问题是怎么消除后效性。 也就是,每次f[i][j][k] 有 (C(i,2) + C(j,2) + C(k,2))/C(i+j+k,2) 的概率走到自己,那么我们用一下生成函数(1+p+p^2+...=1/(1-p))的基本性质就可以算出期望走多少次f[i][j][k],然后再转移即可。
#include<bits/stdc++.h> #define ll long long #define D double using namespace std; D f[105][105][105]; int n,m,k,C[355]; inline void init(){ C[0]=C[1]=0; for(int i=2;i<=320;i++) C[i]=C[i-1]+i-1; } inline void dp(){ f[n][m][k]=1.00; for(int i=n;i>=0;i--) for(int j=m;j>=0;j--) for(int u=k;u>=0;u--) if((i>0)+(j>0)+(u>0)>=2){ f[i][j][u]=f[i][j][u]*C[i+j+u]/(double)(C[i+j+u]-C[i]-C[j]-C[u]); if(i) f[i-1][j][u]+=f[i][j][u]*i*u/(double)C[i+j+u]; if(j) f[i][j-1][u]+=f[i][j][u]*i*j/(double)C[i+j+u]; if(u) f[i][j][u-1]+=f[i][j][u]*j*u/(double)C[i+j+u]; } } inline void output(){ D ans; ans=0; for(int i=1;i<=n;i++) ans+=f[i][0][0]; printf("%.11lf ",ans); ans=0; for(int i=1;i<=m;i++) ans+=f[0][i][0]; printf("%.11lf ",ans); ans=0; for(int i=1;i<=k;i++) ans+=f[0][0][i]; printf("%.11lf",ans); } int main(){ init(); scanf("%d%d%d",&n,&m,&k); dp(); output(); return 0; }
原文地址:https://www.cnblogs.com/JYYHH/p/8597359.html