Test instructions: Given n opponents, at least to defeat the L-person, now has a pocket capacity of K below n numbers indicate the probability of defeating this person
The following n digits (if 1 means that a gold coin can be obtained by defeating the person, if the >0 means that the pocket capacity can be increased to this number)
>=: At least the number of gold coins obtained by defeating the L-individual and obtaining the total pocket capacity. (That is, no gold can be placed at any time)
Idea: Set Dp[i][j][k] indicates that the current former I person has defeated J person, and the remaining pocket capacity of k probability, simply push down the formula can be. One thing that needs to be major, maybe at the beginning
The remaining pocket capacity <0 later than 0, so add a constant does not let it be negative, as long as the last remaining capacity >=0 can be. See the code:
/********************************************************* file name:codeforces167B.cpp Author:kereo Create Time:2 015 Year February 01 Sunday 21:34 15 seconds *********************************************************/#include <iostream># include<cstdio> #include <cstring> #include <queue> #include <set> #include <map># include<vector> #include <stack> #include <cmath> #include <string> #include <algorithm> Using namespace Std;typedef long long ll;const int sigma_size=26;const int n=200+50;const int Maxn=100000+50;const int inf =0x3fffffff;const double eps=1e-8;const int mod=100000000+7, #define L (x) (x<<1) #define R (x) (x<<1|1) # Define PII Pair<int, int> #define MK (x, y) Make_pair ((×), (y)) int n,m,k;int a[n];d ouble p[n],dp[n][n][2*n+10];int Main () {while (~scanf ("%d%d%d", &n,&m,&k)) {memset (dp,0,sizeof (DP)); dp[0][0][n+k]=1.0; for (int i=1;i<=n;i++) {scanf ("%lf", &p[i]); p[i]/=100; } for (int i=1;i<=n;i++) scanf ("%d", &a[i]); for (int i=1;i<=n;i++) {for (int. j=0;j<i;j++) {for (int k=0;k<=2*n;k++) { if (a[i] = =-1) {if (k) dp[i][j+1][k-1]+=dp[i-1][j][k]*p[i]; } else Dp[i][j+1][min (2*n,k+a[i])]+=dp[i-1][j][k]*p[i]; dp[i][j][k]+=dp[i-1][j][k]* (1-p[i]); }}} double ans=0; for (int. i=m;i<=n;i++) for (int j=n;j<=2*n;j++) ANS+=DP[N][I][J]; printf ("%f\n", ans); }return 0;}
Codeforces 167B Wizards and Huge Prize probability DP