Probability dp - cf148D

 Determination of probability should follow the array should seek dp

This state is determined by the initial direction of the recursive

/ * 
The box there are two colors of balls, one is black and the other is white 
AB turns depilling, A preemptive 
A touch randomly each time a ball 
B randomly each time a ball touched, then box throw a ball 
to touch the white ball wins, if not pocket a ball, then B wins 
dp [i] [j]: i left white, black probability j a winning 
three cases 
    a touch of white ball 
    a ball touched the black dragon touch black ball lost black ball 
                         lost white balls                            
* / 
#include <bits / STDC H ++.>
 the using  namespace STD; 

const  Double ESP = 1E- . 7 ;
 const  int MAXN = 1050 ; 

int W, B;
 Double DP [MAXN] [ MAXN]; 

int main () { 
    CIN >> >> W B;
     for(int i=1;i<=w;i++)dp[i][0]=1;
    for(int i=1;i<=w;i++)
        for(int j=1;j<=b;j++){
            dp[i][j]+=(double)i/(i+j);
            if(j>=3)
                dp[i][j]+=(double)j/(i+j) * (double)(j-1)/(i+j-1) * (double)(j-2)/(i+j-2) * dp[i][j-3];
            if(j>=2)
                dp[i][j]+=(double)j/(i+j) * (double)(j-1)/(i+j-1) * (double)i/(i+j-2) * dp[i-1][j-2];
        } 
    printf("%.10lf\n",dp[w][b]);
} 

 

Guess you like

Origin www.cnblogs.com/zsben991126/p/11041866.html