dp[i][j][k]表示到第i个人赢了j个人剩余背包容量为k的情况。
然后转移就可以了。
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; double dp[205][205][405], p[205]; int a[205]; int main() { int n, l, tmp; cin>>n>>l>>tmp; for(int i = 1; i<=n; i++) { cin>>p[i]; p[i]/=100; } for(int i = 1; i<=n; i++) { cin>>a[i]; } dp[0][0][200+tmp] = 1; for(int i = 0; i<n; i++) { for(int j = 0; j<=i; j++) { for(int k = 0; k<=400; k++) { if(a[i+1] == -1) { if(k>0) dp[i+1][j+1][k-1] += dp[i][j][k]*p[i+1]; dp[i+1][j][k] += dp[i][j][k]*(1-p[i+1]); } else { int val = min(400, k+a[i+1]); if(k>0) dp[i+1][j+1][val] += dp[i][j][k]*p[i+1]; dp[i+1][j][k] += dp[i][j][k]*(1-p[i+1]); } } } } double ans = 0; for(int i = l; i<=n; i++) { for(int j = 200; j<=400; j++) { ans += dp[n][i][j]; } } printf("%.8f ", ans); return 0; }