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

hdu1864 最大报销额(01背包)

时间:2018-04-19 15:06:44      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:lan   target   --   false   algorithm   double   class   col   lag   

https://vjudge.net/problem/HDU-1864

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cstdlib>
 6 #include<cmath> 
 7 #define lson l, m, rt<<1
 8 #define rson m+1, r, rt<<1|1
 9 #define IO ios::sync_with_stdio(false);cin.tie(0);
10 #define INF 1e9
11 typedef long long ll;
12 using namespace std;
13 int n, m, a[1010], dp[5000010];
14 double q, price, v[3];
15 int main()
16 {
17     IO;
18     while(~scanf("%lf%d", &q, &n)){
19         int q1 = q*100;
20         if(n == 0) break;
21         memset(dp, 0, sizeof(dp));
22         memset(a, 0, sizeof(a));
23         int t = 0;
24         char type;
25         for(int j = 0; j < n; j++){
26             scanf("%d", &m);
27             for(int i = 0; i < 3; i++) v[i] = 0;
28             int flag=0;
29             for(int i = 0; i < m; i++){
30                 scanf(" %c:%lf", &type, &price);//一张发票上可能有一个物品的多个记录 
31                 if(type==A||type==B||type==C){
32                     int s = type-A;
33                     v[s] += price;
34                 }
35                 else flag=1;
36             }
37             if(flag) a[t]=0;//有‘X‘ 
38             else if(v[0]+v[1]+v[2]>1000) a[t] = 0;//和超 
39             else if(v[0]>600||v[0]>600||v[0]>600) a[t]=0;//单超 
40             else {
41                 a[t] = (v[0]+v[1]+v[2])*100;
42                 t++;
43             } 
44         }
45         //sort(a, a+n);
46         for(int i = 0; i < t; i++){
47             for(int j = q1; j >= a[i]; j--){
48                 dp[j] = max(dp[j], dp[j-a[i]]+a[i]);
49             }
50         }
51         printf("%.2lf\n", dp[q1]*1.0/100);
52     }
53     return 0;
54 }

 

hdu1864 最大报销额(01背包)

标签:lan   target   --   false   algorithm   double   class   col   lag   

原文地址:https://www.cnblogs.com/Surprisezang/p/8882450.html

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