Cf 148d bag of Mice

Source: Internet
Author: User

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}

 

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.