标签:
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; double dp[10005]; int main() { int T,N,sum,money[105]; double P,p[105]; scanf("%d",&T); while(T--) { sum=0; scanf("%lf%d",&P,&N); P=1-P; for(int i=0; i<N; i++) { int d; double f; scanf("%d%lf",&d,&f); money[i]=d; p[i]=1-f; sum+=d; } memset(dp,0,sizeof(dp)); dp[0]=1; for(int i=0; i<N; i++) for(int j=sum; j>=money[i]; j--) { dp[j]=max(dp[j],dp[j-money[i]]*p[i]); } for(int i=sum;i>=0;i--) if(dp[i]>=P) { printf("%d\n",i); break; } } return 0; }
标签:
原文地址:http://www.cnblogs.com/chen9510/p/5509863.html