Probability DP
Kuangbin summed up the third way in the title
It seems that there is no state of entry ah ... It's all about DP. Of course, to find "the transition between states" ...
In the subject Dp[i] and dp[i-(K1+K2+K3)] to Dp[i-1] all have relations ... Then all the dp[i] are related to dp[0] that is ans ...
Use "factor" to transfer ... sigh has been getting more and more water lately.
1 //Bzoj2#include <cmath>3#include <vector>4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <iostream>8#include <algorithm>9 #defineRep (i,n) for (int i=0;i<n;++i)Ten #defineF (i,j,n) for (int i=j;i<=n;++i) One #defineD (i,j,n) for (int i=j;i>=n;--i) A #definePB Push_back - using namespacestd; - intGetint () { the intv=0, sign=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} - while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; + } - Const intn=1e7+Ten, inf=~0u>>2; + /*******************template********************/ A at Doublea[505],b[505],p[ -]; - - intMain () { - //freopen ("Input.txt", "R", stdin); - intt=getint (); - intK1,k2,k3,a,b,c,n; in while(t--){ -N=getint (); K1=getint (); K2=getint (); k3=getint (); toA=getint (); B=getint (); C=getint (); + Doublep0=1.0/k1/k2/K3; -Memset (P,0,sizeofp); theF (I,1, K1) F (J,1, K2) F (k,1, K3) * if(I!=a | | j!=b | | k!=c) p[i+j+k]+=P0; $ Panax NotoginsengD (I,n,0){ -A[i]=p0; b[i]=1; theF (J,1, k1+k2+K3) { + if(i+j>n) Break; Aa[i]+=a[i+j]*P[j]; theb[i]+=b[i+j]*P[j]; + } - } $printf"%.15lf\n", b[0]/(1-a[0])); $ } - return 0; -}View Code
"ZOJ" "3329" one person Game