抢银行,不能高于一个概率p,一共有n个银行。下面是存款+被抓概率;
dp[i][j]表示第i个银行之前,抢到j元的最大逃脱概率。
v[i]是概率,w[i]是钱数;
每次留下w[i]的空间,由之前的那个状态到这个状态(抢这个银行),又因为独立,所以就乘以概率就行;
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]*(1-v[i]));
#include <iostream>
#include <functional>#include <algorithm>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <iomanip>#include <sstream>#include <utility>#include <bitset>#include <cctype>#include <cstdio>#include <limits>#include <memory>#include <string>#include <vector>#include <cmath>#include <ctime>#include <queue>#include <stack>#include <list>#include <map>#include <set>using namespace std;double dp[10000];double v[10000];int w[10000];int main(){ int T,ncas=1; scanf ("%d",&T); while (T--) { memset(dp,0,sizeof(dp)); memset(v,0,sizeof(v)); memset(w,0,sizeof(w)); double temp; int V=0,n; scanf ("%lf%d",&temp,&n); for (int i=1; i<=n; i++) { scanf ("%d%lf",&w[i],&v[i]);// cout<<"temp="<<temp*100.0<<endl; V+=w[i];// cout<<"v[i]="<<v[i]<<endl; }// cout<<V<<endl; int ans=0; dp[0]=1; for (int i=1; i<=n; i++) { for (int j=V; j>=w[i]; j--) { dp[j]=max(dp[j],dp[j-w[i]]*(1-v[i]));// printf ("dp[%d]=%d,",j,dp[j]); }// printf ("\n");// for (int j=0;j<=V;j++)// { // printf ("%d ",dp[j]);// }// printf ("\n"); } int i; for (i=V;i>=0;i--) if (dp[i]>1-temp) break; printf ("Case %d: %d\n",ncas++,i); } return 0;}