Test instructions: There are n banks, each robbing a bank, can get (v_i\) before, but there will be (p_i\) probability of being caught. Now you have to control the probability of being caught under \ (p\) , to find out how much money can be robbed.
Analysis: 0-1 The deformation of the backpack, the weight into a probability, because the calculation of probability requires the product rather than the addition, so can not be directly used Dp[j] to express the probability of J maximum profit.
Make \ (dp[i][j]\) indicates to the former \ (i\) Bank, the probability that the value is (j\) can still remain secure, then there is a recursive type:
\[DP[I][J] = dp[i-1][j-v[i]]* (1-p[i]) \]
The first dimension can actually save, because it is related to the previous item, then push backwards like a 0-1 backpack.
Finally, we can find the maximum benefit that satisfies the safety probability.
#include <bits/stdc++.h>using namespace std; #define EPS 1e-7const int maxn = 1e4+5;typedef Long Long ll;d Ouble dp[maxn],p[maxn];int V[maxn];int Main () {#ifndef Online_judge freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); #endif int T; scanf ("%d", &t); Dp[0] = 1.0; while (t--) {int n,sum=0; Double P; cin>>p>>n; P = 1-p; Memset (Dp,0,sizeof (DP)); Dp[0] = 1; for (int i=1;i<=n;++i) {cin>>v[i]>>p[i]; P[i] = 1-p[i]; Sum + = V[i]; } for (int i=1;i<=n;++i) {for (int j=sum;j>=v[i];--j) {if (Dp[j-v[i]]*p[i] > Dp[j]) DP[J] = dp[j-v[i]]* P[i]; }} for (int i=sum;i>=0;--i) {if (dp[i]>p) {cout<<i<<endl; Break }}}} return 0;}
hdu--2955 robberies (0-1 backpack)