标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<iostream>
#include<cstdio>
using namespace std;
int m[105];
double dp[10010],v[105];
int main()
{
int t,n,sum,i,j;
double p;
cin>>t;
while(t--){
scanf("%lf %d",&p,&n);
sum=0;
p=1-p;
for(i=0;i<n;i++){
scanf("%d %lf",&m[i],&v[i]);
sum+=m[i];
v[i]=1-v[i];
}
for(i=0;i<=sum;i++) dp[i]=0;
dp[0]=1;
for(i=0;i<n;i++){
for(j=sum;j>=m[i];j--){
dp[j]=max(dp[j],dp[j-m[i]]*v[i]);
}
}
for(i=sum;i>=0;i--){
if(dp[i]>p){
printf("%d\n",i);
break;
}
}
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/wangdongkai/p/5357624.html