Test instructions
n individuals, starting with a capacity of a K-pack, defeating a person's backpack can get a certain capacity or get a fortune (put in a backpack), give the probability of defeating each person, and ask at least to beat the L person, and the backpack capacity is greater than the probability of total wealth obtained
Analysis:
State OK, Dp[i][j][k] said before I personally beat J backpack capacity is k is the probability, the probability is pushing, to pay attention to the backpack capacity can be negative, we add capacity to B.
#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)#defineB 201Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[ About][ About][2*b+Ten];inta[ About],p[ About];intn,l,k;voidsolve () {memset (DP,0,sizeof(DP)); dp[0][0][b+k]=1; for(intI=1; i<=n;++i) for(intj=0; j<=i;++j) for(intk=0; k<=2*b;++k) {Dp[i][j][k]+=dp[i-1][j][k]* (1-p[i]/100.0)//did not beat the first I personif(a[i]==-1){ if(k>0)//must be able to put down a fortune dp[i][j+1][k-1]+=dp[i-1][j][k]* (p[i]/100.0); } Else{ if(k+a[i]>2*B) Dp[i][j+1][2*b]+=dp[i-1][j][k]* (p[i]/100.0); Elsedp[i][j+1][k+a[i]]+=dp[i-1][j][k]* (p[i]/100.0); } }
The probability of qualifying conditions andDoubleTotal=0.0; for(intj=l;j<=n;++j) for(intk=b;k<=2*b;++k) Total+=Dp[n][j][k]; printf ("%.12lf\n", total);}intMain () { while(~SCANF ("%d%d%d",&n,&l,&k)) { for(intI=1; i<=n;++i) scanf ("%d",&P[i]); for(intI=1; i<=n;++i) scanf ("%d",&A[i]); Solve (); }return 0;}
Codeforces 167B Wizards and Huge Prize (probabilistic DP)