Codeforces 540D bad Luck Island-probability + memory Search

Source: Internet
Author: User

Test instructions

There are three species of a,b,c on an island, and how many of them will tell you in the input, up to 100 each

A and B meet, A will eat B,

B and C, B will eat C,

C and a meet, C will eat a ... I can't help but want to spit this ring food chain

The meeting was random. On the last island there was only one creature, asking what the probability of the creature was a,b,c.

Exercises

Actually very simple, this problem, the state equation is very good to think.

Set DP[I][J][K] for biological A has I only, biological B has j only, Bio C has k only probability situation, it is obvious that the return value of DP should have three, respectively, is the probability of the last species left

Then we consider the situation of state transitions.

If A and B meet, the probability is P1 = i*j/(i*j+j*k+k*i), in this case, B will be eaten by a, so the number of B is reduced by 1, showing that it is dp[i][j][k]= P1*dp[i][j-1][k] (DP 3 of the return values are involved in the calculation)

B and C meet, and A and C meet as well.

Using the full probability formula, the final state transfer equation is dp[i][j][k]= i*j/sum * Dp[i][j-1][k] + j*k/sum * dp[i][j][k-1] + k*i/sum *dp[i-1][j][k]

where Sum=i*j+j*k+k*i (I*j/sum, J*k/sum, K*i/sum and 1 in the full probability formula are satisfied)

#include <bits/stdc++.h>#defineEPS 1e-9#definefor (i,j,k) for (int i=j;i<=k;i++)#defineMAXN 1005#defineMAXM 40005#defineINF 0X3FFFFFFF#definePB push_back#defineMP Make_pair#defineX First#defineY Second#defineLC (K&LT;&LT;1)#defineRC ((k<<1) 1)using namespaceStd;typedefLong LongLL;intI,j,k,n,m,x,y,t,ans,big,cas,num,len;BOOLFlag;structnode{Doublex, Y, Z Node () {} node (DoubleXDoubleYDoublez): X (x), Y (y), Z (z) {}}dp[ the][ the][ the];BOOLvis[ the][ the][ the];node DFS (intAintBintc) {    if(Vis[a][b][c])returnDp[a][b][c]; VIS[A][B][C]=1; intsum=a*b+b*c+a*C; Node R=node (0,0,0), S=node (0,0,0), T=node (0,0,0), RT; if(b>0) R=dfs (a,b-1, c);Doublep1=a*b*1.0/sum; if(c>0) S=dfs (a,b,c-1);Doublep2=b*c*1.0/sum; if(a>0) T=dfs (A-1, b,c);Doublep3=c*a*1.0/sum; Rt.x=p1*r.x+p2*s.x+p3*T.x; Rt.y=p1*r.y+p2*s.y+p3*T.y; Rt.z=p1*r.z+p2*s.z+p3*t.z; returndp[a][b][c]=RT;}intMain () {intA,b,c; scanf ("%d%d%d",&a,&b,&c); memset (Vis,0,sizeof(VIS));  for(i=1; i<= -; i++) {vis[0][0][i]=1; dp[0][0][i].z=1; vis[0][i][0]=1; dp[0][i][0].y=1; vis[i][0][0]=1; dp[i][0][0].x=1; } node ans=DFS (A,B,C); Memset (DP,-1,sizeof(DP)); printf ("%.12f%.12f%.12f\n", ans.x,ans.y,ans.z); return 0;}

Codeforces 540D bad Luck Island-probability + memory Search

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.