Probability, $DP $.
$DP [i][j][0]$ says there is still $i$ a white cat, $j $ A black cat, the probability of the princess reaching the target State in case of a shot.
$DP [i][j][1]$ says there is still $i$ a white cat, $j $ A black cat, the probability of reaching the target State in case of a dragon shot.
At first $dp[i][0][0]$ are $1$, the answer is $dp[w][b][0]$. The recursive type is easy to write:
$DP [i][j][0]=i/(I+J) +j/(i+j) *dp[i][j-1][1]$
$DP [i][j][1]=j/(I+J) *i/(i+j-1) *dp[i-1][j-1][0]+j* (j-1)/((i+j) * (i+j-1)) *dp[i][j-2][0]$
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-6;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} Template<classT>inlinevoidRead (T &x) { Charc =GetChar (); X=0; while(!isdigit (c)) C =GetChar (); while(IsDigit (c)) {x= x *Ten+ C-'0'; C=GetChar (); }}Doubledp[1005][1005][2];intw,b;intMain () { while(~SCANF ("%d%d",&w,&b) {memset (DP,0,sizeofDP); for(intI=1; i<=w;i++) dp[i][0][0]=1; for(intI=1; i<=w;i++) { for(intj=1; j<=b;j++) {dp[i][j][0]=1.0*i/(I+J) +1.0*j/(I+J) *dp[i][j-1][1]; dp[i][j][1]=1.0*j/(i+j) *i/(i+j-1) *dp[i-1][j-1][0]; if(j>=2) dp[i][j][1]+=1.0*j* (J-1)/((i+j) * (i+j-1)) *dp[i][j-2][0]; }} printf ("%.9f\n", dp[w][b][0]); } return 0;}
Codeforces 148D Bag Of Mice