Codeforces Round #301 (Div. 2)---D. Bad Luck (probabilistic DP)

Source: Internet
Author: User

The bad Luck are inhabited by three kinds of species:r rocks, s scissors and P papers. At some moments of time both random individuals meet (all pairs of individuals can meet equiprobably), and if they belong t o different species, then one individual kills the other one:a rock kills scissors, scissors kill paper, and paper kills A rock. Your task is to determine for each species, what's the probability, this species would be, the only one to inhabit this Island after a long enough period of time.
Input

The single line contains three integers r, s and P (1?≤?r,?s,?p?≤?100)-the original number of individuals in the species Of rock, scissors and paper, respectively.
Output

Print three space-separated real numbers:the probabilities, at which the rocks, the scissors and the paper'll be is the on ly surviving species, respectively. The answer would be a considered correct if the relative or absolute error of each number doesn ' t exceed?-? 9.
Sample Test (s)
Input

2 2 2

Output

0.333333333333 0.333333333333 0.333333333333

Input

2 1 2

Output

0.150000000000 0.300000000000 0.550000000000

Input

1 1 3

Output

0.057142857143 0.657142857143 0.285714285714

DP[R][S][P] Indicates the probability that there is a rock,s scissors,p papers of R left.

/************************************************************************* > File name:d.cpp > Author:al ex > Mail: [email protected] > Created time:2015 May 01 Friday 20:06 20 seconds ************************************** **********************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Doubledp[101][101][101];intMain () {intR, S, p; while(Cin>> R >> s >> p) { for(inti =0; I <= R; ++i) { for(intj =0; J <= S; ++J) { for(intK =0; K <= P; ++K) {Dp[i][j][k] =0; }}} Dp[r][s][p] =1; for(inti = r; I >=0; -I.) { for(intj = S; J >=0; --J) { for(intK = p; K >=0; --K) {DoublePP =0;if(i + j + K <1) {Continue; }if(I >1) {pp + = i * (i-1) *1.0/2; }if(J >1) {pp + = J * (J-1) *1.0/2; }if(k >1) {pp + k * (K-1) *1.0/2; }Doublex = ((i + j + k +1) * (i + j + k) *1.0) /2;if(i + j + k >1) {pp/= ((i + j + k) * (i + j + K-1)) /2; }Else{pp =0; }DoubleTMP =0;if(i +1<= r && k >0) {Dp[i][j][k] + = Dp[i +1][J][K] * ((i +1) * k *1.0)/x; }if(j +1<= s && i >0) {Dp[i][j][k] + = Dp[i][j +1][K] * ((j +1) * I *1.0)/x; }if(k +1<= P && J >0) {Dp[i][j][k] + = Dp[i][j][k +1] * ((k +1) * J *1.0)/x; }if(pp! =1.0) {Dp[i][j][k]/= (1.0-PP); }//dp[i][j][k] + = tmp;            //printf ("dp[%d][%d][%d] =%lf\n", I, J, K, Dp[i][j][k]);}            }        }DoubleANS1 =0, Ans2 =0, ANS3 =0; for(inti =1; I <= R; ++i) {ans1 + = dp[i][0][0]; } for(inti =1; I <= s; ++i) {ans2 + = dp[0][i][0]; } for(inti =1; I <= p; ++i) {ans3 + = dp[0][0][i]; }printf("%.12f%.12f%.12f\n", Ans1, Ans2, ANS3); }return 0;}

Codeforces Round #301 (Div. 2)---D. Bad Luck (probabilistic 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.