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