Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10526 Accepted Submission(s): 3868
ios
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 #define MAX 10003 5 double p[MAX],f[MAX]; 6 int m[103]; 7 int main() 8 { 9 double P; 10 int T, N, i, j; 11 cin>>T; 12 while(T--) 13 { 14 int sum = 0; 15 scanf("%lf %d",&P,&N); 16 P = 1-P; //不被抓的機率 17 for(i=0; i<N; i++) 18 { 19 scanf("%d %lf",&m[i],&p[i]); 20 p[i] = 1-p[i]; //不被抓的機率 21 sum += m[i]; //能夠搶到的最大金錢數目 22 } 23 24 for(i=0; i<=sum; i++) 25 f[i] = 0; 26 f[0] = 1; //表示搶金錢爲0的時候,不被抓的機率爲1 27 for(i=0; i<N; i++) 28 for(j=sum; j>=m[i]; j--) 29 f[j] = max(f[j],f[j-m[i]]*p[i]); 30 for(i=sum; i>=0; i--) //從最大的金錢數目開始,依次查看不被抓機率是否和給定的相等 31 if(f[i]-P>0.000000001) 32 { 33 cout<<i<<endl; 34 break; 35 } 36 } 37 return 0; 38 }