ZOJ 3329-one Person Game (probabilistic DP, iterative processing ring)

Source: Internet
Author: User

Test instructions

Three dice have k1,2,k3 face each side of the label (1-K1,1-K2,1-K3), three dice at a time, the positive upward of three numbers, if the three designator and the given three number a1,b1,c1 corresponds to the sum of zero, otherwise the sum plus three dice marking and, until the sum is not less than n when the end, The desired number of times to ask for a parabolic boson.

Analysis:

The state of the problem is good analysis

Dp[i] represents and is the desired number of times for I, dp[0] is the answer

Dp[i]=sum (Dp[i+tmp]*p[tmp]) +dp[0]*p0+1 (TMP is the three dice can be obtained the marking and);

The first time to see such an equation is not solved, see the solution to know with the iterative method, each dp[i] includes dp[0];

Dp[i]=a[i]*dp[0]+b[i], brought into the above equation can be dp[i]= (sum (a[i+tmp]*p[tmp]) +p0) *dp[0]+sum (b[i+tmp]*p[tmp]) +1;

Then A[i]=sum (a[i+tmp]*p[tmp]) +p0,b[i]=sum (b[i+tmp]*p[tmp]) +1;

Then dp[0]=a[0]*dp[0]+b[0], to find out the answer;

#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doublea[1010],b[1010],p[ -];intn,k1,k2,k3,a1,b1,c1;voidsolve () {Doubletp=1.0/(k1*k2*K3); Memset (P,0,sizeof(p)); Memset (A,0,sizeof(a)); memset (b,0,sizeof(b));  for(intI=1; i<=k1;++i) for(intj=1; j<=k2;++j) for(intk=1; k<=k3;++k)if(i!=a1| | j!=b1| | k!=C1) P[i+j+k]+=TP;  for(inti=n;i>=0;--i) {     for(intj=3;(i+j) <=n&&j<=k1+k2+k3;++j) {A[i]+=a[i+j]*P[j]; B[i]+=b[i+j]*P[j]; } A[i]+=TP; B[i]+=1.0; } printf ("%.15lf\n", b[0]/(1.0-a[0]));}intMain () {intT; scanf ("%d",&t);  while(t--) {scanf ("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a1,&b1,&C1);    Solve (); }return 0;}

ZOJ 3329-one Person Game (probabilistic DP, iterative processing ring)

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.