Title Link: Http://www.codeforces.com/problemset/problem/148/D
Test instructions: A bag with white mouse and Black mouse, dragon and Princess take turns to catch one, Dragon grabbed a will scare off a mouse, princess first catch, who first caught White mouse who win, ask Princess win probability is how much?
Idea: Dp[i] means princess The first round win, the answer is dp[1] + dp[2] + dp[3] + ...
Assume
Princess won the first round. dp[1] = w/(w + b);
Princess won in the second round. dp[2] = W * b * (b-1)/((w + b) * (w + b-1) * (W + b-2));
Princess won in the third round. Dp[3] = W * b * (b-1) * (b-2) * (b-3)/((w + b) * (w + b-1) * (w + b-2) * (w + b-3) * (W + b -4));
。。。
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <cmath>8#include <queue>9#include <Set>Ten#include <map> One #defineINF 0x3f3f3f3f A using namespacestd; -typedefLong LongLL; - the Doubledp[1010]; - intMain () - { - intW, b; +scanf"%d%d", &w, &b); - Doubleres =0; + if(b = =0&& W! =0) A { atres =1; - } - Else if(W! =0&& B! =0) - { -dp[1] = W *1.0/(W +b); - intj =2, k = (int) ((w + b) *1.0/3); in if((w + b) *1.0/3> (int) ((w + b) *1.0/3)) -k++; to for(inti = b; J <= K; I-=2, J + +) + { -DP[J] = dp[j-1] * I * (i-1) *1.0/((w + i-1) * (w + i-2)); the } * for(inti =1; I < J; i++) $Res + =Dp[i];Panax Notoginseng } -printf"%.9lf\n", res); the return 0; +}View Code
Codeforces148d_ Inference Problem