Cdoj 1135 Qiu teacher watching movie probability dp

Source: Internet
Author: User

Miss Qiu is watching a movieTime limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others) Submit Status

One day Qiu teacher whim want to go to the movies, but Miss Qiu's sister want to go shopping, they no way to persuade each other, so ready to play a game to decide who to listen to.

Qiu teacher Find W only mouse and B black rat, Qiu teacher and sister take turns from the bag inside Catch mouse, who first caught White mouse who won.

But there is the sauce God in the side of the trouble, Qiu teacher every catch a mouse out, sauce God secretly also grabbed a out from inside, these 3 people caught out of the mice are random.

If there is no white mouse in the bag, and no one has ever taken the White mouse, Miss Qiu wins.

In order to embody the gentleman spirit, Qiu teacher let sister catch first, then sister win probability is how much?

Input

Only two digits W and b w<=1000 b<=1000

Output

The odds of a sister winning 9 decimal places

Sample input and output
Sample Input Sample Output
1 3
0.500000000
SourceUESTC Training for Dynamic programming
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm > #include <set>using namespace std;typedef long long ll;typedef unsigned long long Ull; #define MM (A, B) memset (A, B , sizeof (a)); const double EPS = 1e-10;const int inf =0x7f7f7f7f;const double pi=acos ( -1); const int n=1005;double dp[n][n];     int main () {for (int i=1;i<=1000;i++) {dp[0][i]=0;dp[i][0]=1;}         for (int i=1;i<=1000;i++) {double ix=i;     dp[i][1]=ix/(ix+1);     } DP[1][2]=1.0/3;         for (int i=2;i<=1000;i++) {double ix=i;     dp[i][2]=ix/(ix+2) +2/(ix+2) *1/(ix+1);             } for (int w=1;w<=1000;w++) for (int b=3;b<=1000;b++) {double w1=w,b1=b; dp[w][b]=w1/(W1+B1) + b1/(W1+B1) * (b1-1)/(w1+b1-1) * (w1/(w1+b1-2) *dp[w-1][b-2]+ (b1-2)/(W1+b1-2) *dp[w][b-3]);     } int w,b;     while (~SCANF ("%d%d", &w,&b)) printf ("%.9f\n", Dp[w][b]); return 0;}

 Probability Recurrence formula:

dp[w][b]=w1/(W1+B1) + b1/(W1+B1) * (b1-1)/(w1+b1-1) * (w1/(w1+b1-2) *dp[w-1][b-2]+ (b1-2)/(W1+b1-2) *dp[w][b-3]);
So we need to preprocess the dp[0][i],dp[i][0],dp[i][1],dp[i][2] four special cases

Cdoj 1135 Qiu teacher watching movie probability dp

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.