码迷,mamicode.com
首页 > 其他好文 > 详细

hdu_1203

时间:2015-03-10 21:02:11      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

原来这叫背包..

 1 #include <cstdio>
 2 #include <algorithm>
 3 
 4 // dp[i] is the possibility he can get at least 1 offer when i yuan have been taken. 
 5 int n, m, a[10010];
 6 double dp[10010], b[10010];
 7 
 8 int main(int argc, char const *argv[])
 9 {
10     // freopen("_in", "r", stdin);
11     while(scanf("%d%d", &n, &m)){
12         if(n==0 && m==0)
13             break;
14         for(int i = 1; i <= m; ++i)
15             scanf("%d %lf", a+i, b+i);
16 
17         for(int i = 0; i <= n; ++i)
18             dp[i] = 1.0;
19 
20         for(int i = 1; i <= m; ++i)
21             for(int j = n; j >= a[i]; --j)
22                 dp[j] = std::min(dp[j], dp[ j-a[i] ]*(1-b[i]) );    
23 
24         
25             
26         printf("%.1lf%%\n", (1-dp[n])*100 );
27     }
28     return 0;
29 }

 

hdu_1203

标签:

原文地址:http://www.cnblogs.com/takeoffyoung/p/4327737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!