标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15522 Accepted Submission(s): 5708
#include<stdio.h> #include<string.h> #define MAX 10001 #define max(x,y)(x>y?x:y) int price[110]; double wei[110],dp[MAX]; int main() { int n,j,i,t,money; double p,w; scanf("%d",&t); while(t--) { scanf("%lf%d",&w,&n); money=0; for(i=0;i<n;i++) { scanf("%d%lf",&price[i],&wei[i]); money+=price[i]; wei[i]=1-wei[i]; } memset(dp,0,sizeof(dp)); dp[0]=1; for(i=0;i<n;i++) { for(j=money;j>=price[i];j--) { dp[j]=max(dp[j],dp[j-price[i]]*wei[i]); } } p=1-w; for(i=money;i>=0;i--) { if(dp[i]>=p) { printf("%d\n",i); break; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4612786.html