First probability expectation DP:)
In fact, and the general DP is similar, as long as the status of the election is OK.
Definition dp[i][j] means I have only white mouse J Black Mouse when the princess won the probability.
Then: 1. Princess Choose white Mouse, direct win, probability: i/(I+J)
2. The princess chose the black Mouse
1) The Dragon chose the black Mouse, fled the black mouse; probability: j/(i+j) * (j-1)/(i+j-1) * (j-2)/(I+j-2)
2) Dragon Choose Black Mouse, Escape white mouse; probability: j/(i+j) * (j-1)/(i+j-1) *i/(i+j-2)
3) Long Mouse, so the princess will lose, do not consider
Then dp[i][j] equals the sum of the above probabilities.
When initialized, the probability of winning is 1 if only microscope
If the black mouse wins, the odds are 0.
The code is as follows:
#include <iostream> #include <cstdio> #include <cstring>using namespace std;double dp[1100][1100]; int main () { int w,b; while (scanf ("%d%d", &w,&b)!=eof) {for (int i=1;i<=w;i++) dp[i][0]=1; for (int j=1;j<=b;j++) dp[0][j]=0; for (int i=1;i<=w;i++) for (int j=1;j<=b;j++) { dp[i][j]=1.0*i/(i+j); if (j>=3) dp[i][j]+=j*1.0/(i+j) * (j-1) *1.0/(i+j-1) * (j-2) *1.0/(i+j-2) *dp[i][j-3]; if (j>=2) dp[i][j]+=j*1.0/(i+j) * (j-1) *1.0/(i+j-1) *i*1.0/(i+j-2) *dp[i-1][j-2]; } printf ("%.9lf\n", Dp[w][b]); } return 0;}
Cf148d--bag of mice+ probability expectation DP