http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754
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