标签:des style blog class c code
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 10526 Accepted
Submission(s): 3868
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 }
Hdu 2955 Robberies,布布扣,bubuko.com
标签:des style blog class c code
原文地址:http://www.cnblogs.com/yazhou/p/3738396.html