ZOJ 3329 One person Game probability dp expected difficulty: 2

Source: Internet
Author: User


The probability of a subject score of 0 is uncertain, so it is not possible to proceed from the 0 end.

Set E[i] to reach the number of steps required for success, obviously i>n when e[i]=0, when 0<i<=n e[i]=sigma (E[I+K]*PK) +e[0]*p0, (K can be cast except for the sum of the dice just for a,b,c),

In this formula, E[i] and e[0] are unknown, set e[0]=x, then

E[i]=sigma (E[I+K]*PK) +x*p0+1,

Because all J of the greater than I, satisfies the e[j] of the first term and 0 times the term is known, obviously, can be used X to represent all E[i],

Set E[i], the first item part is a[i], the constant term part is b[i], gradually recursion, you can get e[0]=a[0]*e[0]+b[0], then e[0] can be solved, that is, the answer

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn=505;Const intmaxk=7;Doublep[maxk*3],DPA[MAXN],DPB[MAXN];intn,k1,k2,k3,a,b,c;intSUMK;DoubleMulk;voidinit () {SUMK=k1+k2+K3; Mulk=k1*k2*K3; Memset (P,0,sizeof(p)); p[0]=1/Mulk;  for(intI=1; i<=k1; i++)        {             for(intj=1; j<=k2; J + +)            {                 for(intk=1; k<=k3; k++)                {                    if(i!=a| | j!=b| | K!=c) {p[i+j+k]+=1/(Mulk);} }            }        }}voidCalc () { for(inti=n;i>=0; i--) {Dpa[i]=p[0]; Dpb[i]=1;  for(intj=3; j<=sumk&&i+j<=n;j++) {Dpa[i]+=dpa[i+j]*P[j]; Dpb[i]+=dpb[i+j]*P[j]; }    }}intMain () {intT; scanf ("%d",&T);  for(intTi=1; ti<=t; ti++) {scanf ("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&a,&b,&c);        Init ();        Calc (); printf ("%.15f\n", dpb[0]/(1-dpa[0])); }    return 0;}

ZOJ 3329 One person Game probability dp expected difficulty: 2

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.