The theme: Beauty and the Beast are playing the game of painting pigeons. Pigeons in the cage covered with black cloth, white w only, Black has B, each time to take out a painting, who first painted white pigeons who will win. Beauty first draw, because the beast is too ugly, it every time the painting will scare away a pigeon, all the pigeons out of the cage are not in. Ask beauty to win probability. (Set if no one draws the white dove, count the Beast to win).
Problem Analysis: This problem is not difficult, it is obvious that the probability of DP. This is my first time to write a probability dp, to commemorate ...
The code is as follows:
# include<iostream># include<cstdio># include<vector># include<list># include<queue># include<cstring># include<set># include<map># include <string># include<cmath># include<algorithm>using namespace std;double dp[1005][1005];d ouble DP ( int W,int b) {if (dp[w][b]!=-1.0) return dp[w][b]; if (w<=0) return dp[w][b]=0.0; if (b<=0) return dp[w][b]=1.0; Double res1= (Double) w/(double) (w+b); Double res2= (double) b/(double) (w+b)) * ((double) (b-1)/(double) (w+b-1)); Double t=0.0; if (b-2>0) t+= ((double) (b-2)/(double) (w+b-2)) *DP (w,b-3); if (w-1>0) t+= ((double) (w)/(double) (w+b-2)) *DP (w-1,b-2); res2*=t; return dp[w][b]=res1+res2;} int main () {int w,b; while (~SCANF ("%d%d", &w,&b)) {for (Int. i=0;i<=w;++i) for (int j=0;j<=b;++j) dp[i][j]=-1.0; printf ("%.9lf\n", DP (w,b)); } return 0;}
Coderforce 148d-bag Of Mice (probability DP seeking probability)