The dragon selects a mouse and then runs away
The princess chooses a mouse and won't run out of another mouse.
Evaluate the probability of winning the princess
1 # include <iostream> 2 # include <string> 3 # include <cstdio> 4 # include <vector> 5 # include <queue> 6 # include <stack> 7 # include <algorithm> 8 # include <cstring> 9 # include <stdlib. h> 10 # include <cmath> 11 using namespace STD; 12 # define Pb push_back13 double DP [1010] [1010]; 14 int main () {15 int W, B; 16 while (CIN> W> B) {17 memset (DP, 0, sizeof (DP); 18 DP [1] [0] = 1; 19 For (INT I = 1; I <= W; I ++) 20 for (Int J = 0; j <= B; j ++) {21 double P1, p2; 22 int A = I, B = J; 23 DP [I] [J] = 1.0 * I/(I + J); 24 if (B> = 1) {25 p1 = 1.0 * B/(a + B); 26 B --; // The Princess selects a 27 if (B> = 1) {28 P2 = 1.0 * B/(a + B); // select 29 B for the dragon --; 30 if (B> = 1) 31 DP [I] [J] + = p1 * P2 * B/(a + B) * DP [I] [J-3]; 32 DP [I] [J] + = p1 * P2 * A/(a + B) * DP [I-1] [J-2]; 33} 34} 35} 36 printf ("%. 10lf \ n ", DP [w] [B]); 37} 38}