Codeforces148d_ Inference Problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.