"Codeforces" "148D" Bag Of Mice

Source: Internet
Author: User

Probability DP

The 9th question in Kuangbin summary

Ah ... The data given by the topic are only the number of rats and black rat, so we can only do this (GAO) (P).

Obviously can use the number of two kinds of mice as state = =

My WA Approach:

Make F[i][j] said from (w,b) take the mouse one until (i,j) "This time round process take" two people have been dead heat probability, it is obvious (I,J) This state win probability is I/(I+J), then the probability of total win is all (I,j), f[i][j]*i/( I+J) sum

Transfer of course is very simple ~ F[i][j] can only from f[i][j+3] (two people caught a black rat, scare out a black rat) and f[i+1][j+2] (two people grabbed a black rat, scared out a white mouse) two states transferred over.

So there are f[i][j]= f[i+1][j+2]* (j+2)/(i+j+3) * (j+1)/(i+j+2) * (i+1)/(i+j+1) + f[i][j+3]* (j+3)/(i+j+3) * (j+2)/(i+j+2) * (j+1)/( I+J+1);

Reverse push from f[n][m]=1.0, add ans to each step

I was at the 9th Point on WA ... I guess it's a burst of precision ... sigh,1e-9 's accuracy is not hurt.

Kuangbin's AC approach:

F[I][J] is represented as a wheel to process grasp when I only white, J Black, she won the probability. Transfer is similar, but this is high accuracy (unlike I have to add additional?) In fact, I don't understand why ... Anyway, the accuracy will be much better ...

1 //CF 148D2#include <cmath>3#include <vector>4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <iostream>8#include <algorithm>9 #defineRep (i,n) for (int i=0;i<n;++i)Ten #defineF (i,j,n) for (int i=j;i<=n;++i) One #defineD (i,j,n) for (int i=j;i>=n;--i) A #definePB Push_back - using namespacestd; - intGetint () { the     intv=0, sign=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; + } - Const intn=1010, inf=~0u>>2; + Const Doubleeps=1e-Ten; A /*******************template********************/ at DoubleF[n][n]; - intMain () { -     intN=getint (), m=getint (); -     Doubleans=0.0; -F (I,1, N) f[i][0]=1.0; -F (J,1, m) f[0][j]=0.0; inF (I,1, N) F (J,1, M) { -F[i][j]= (Double) i/(i+j); to         if(j>=3) f[i][j]+=f[i][j-3]*j/(I+J) * (J-1)/(i+j-1) * (J-2)/(i+j-2); +         if(j>=2) f[i][j]+=f[i-1][j-2]*i/(i+j) *j/(i+j-1) * (J-1)/(i+j-2); -     } theprintf"%.9lf\n", F[n][m]); *     return 0; $}
View Code

"Codeforces" "148D" Bag Of Mice

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.