Links: Http://codeforces.com/problemset/problem/540/D
Main topic:
This island has three species of bio R stone s Scissors p cloth
To find the probability of only one living creature left.
Use Dp[i][j][k] to represent probabilities
The probability that the stone and the scissors Meet is p=i*j/(i*j+j*k+k*i), the scissors will be eaten so dp[i][j-1][k]=dp[i][j][k]*p, each situation will have three kinds of circumstances evolved, so every time to add him
The code should look at the code to understand
#include <stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<queue>#defineN 110using namespacestd;DoubleDp[n][n][n];intMain () {intr,s,p,i,j,k; while(SCANF (" %d%d%d", &r,&s,&p)! =EOF) {memset (DP,0,sizeof(DP)); DP[R][S][P]=1.0; for(i=r;i>=0; i--) { for(j=s;j>=0; j--) { for(k=p;k>=0; k--) { Doublesum=i*j+j*k+k*i; if(I &&k) Dp[i-1][j][k]+=dp[i][j][k]*i*k*1.0/sum; if(J &&i) dp[i][j-1][k]+=dp[i][j][k]*i*j*1.0/sum; if(k &&j) Dp[i][j][k-1]+=dp[i][j][k]*k*j*1.0/sum; } } } Doublex=0, y=0, z=0; for(i=r;i>0; i--) x+=dp[i][0][0]; for(i=s;i>0; i--) y+=dp[0][i][0]; for(i=p;i>0; i--) Z+=dp[0][0][i]; printf ("%.12lf%.12lf%.12lf\n", x, Y, z); } return 0;}
Bad Luck Island-codeforce (DP)