标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 const int maxn=10005; 7 8 int main() 9 { 10 double P; 11 double p[maxn],dp[maxn]; 12 int t,total,n,i,j; 13 int v[maxn]; 14 scanf("%d",&t); 15 while(t--) 16 { 17 memset(dp,0,sizeof(dp)); 18 scanf("%lf%d",&P,&n); 19 for(total=0,i=0;i<n;i++) 20 { 21 scanf("%d%lf",&v[i],&p[i]); 22 total+=v[i]; 23 } 24 dp[0]=1; 25 for(i=0;i<n;i++) 26 for(j=total;j>=v[i];j--) 27 { 28 dp[j]=max(dp[j],dp[j-v[i]]*(1-p[i])); 29 } 30 for(i=total;i>=0;i--) 31 if(dp[i]>=1-P) 32 { 33 printf("%d\n",i); 34 break; 35 } 36 } 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4768766.html