标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <stdio.h> 2 #include <string.h> 3 double P[105],dp[10005]; 4 int N[105]; 5 double max(double x,double y) 6 { 7 8 return x>y?x:y; 9 } 10 11 int main() 12 { 13 int T; 14 scanf("%d",&T); 15 while(T--) 16 { 17 int n,total=0; 18 double p; 19 scanf("%lf%d",&p,&n); 20 for(int i=0; i<n; i++) 21 { 22 scanf("%d%lf",&N[i],&P[i]); 23 total+=N[i]; 24 } 25 //printf("total=%d\n",total); 26 memset(dp,0,sizeof(dp)); 27 dp[0]=1; 28 for(int i=0; i<n; i++) 29 { 30 31 for(int j=total; j>=N[i]; j--) 32 { 33 34 dp[j]=max(dp[j],dp[j-N[i]]*(1-P[i])); 35 36 } 37 } 38 for(int i=total; i>=0; i--) 39 { 40 41 if(dp[i]>=1-p) 42 { 43 printf("%d\n",i); 44 break; 45 } 46 47 } 48 } 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/huangguodong/p/4734802.html