# 最大报销额

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 27194    Accepted Submission(s): 8351

Problem Description

Input

m Type_1:price_1 Type_2:price_2 ... Type_m:price_m

Output

Sample Input
200.00 3 2 A:23.50 B:100.00 1 C:650.00 3 A:59.99 A:120.00 X:10.00 1200.00 2 2 B:600.00 A:400.00 1 C:200.50 1200.50 3 2 B:600.00 A:400.00 1 C:200.50 1 A:100.00 100.00 0

Sample Output
123.50 1000.00 1200.50

Source

 1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <cstring>
5 #define rep(i,l,r) for(int i = l; i <= r; i++)
6 #define clr(x,y) memset(x,y,sizeof(x))
7 #define travel(x) for(Edge *p = last[x]; p; p = p -> pre)
8 using namespace std;
9 int N, dp[3000010], rec[31];
10 float q, X;
11 char type;
12 void work(){
13     int Q = (int) (q * 100);
14     clr(dp,0); int recCnt = 0;
15     rep(i,1,N){
16         int typeCnt;
17         int sum = 0, A = 0, B = 0, C = 0;
18         bool flag = 1;
19         scanf("%d",&typeCnt);
20         rep(j,1,typeCnt){
21             getchar();
22             scanf("%c:%f",&type,&X);
23             int x = (int) (X * 100);
24             sum += x;
25             if (type == 'A') A += x;
26             else if (type == 'B') B += x;
27             else if (type == 'C') C += x;
28             else flag = 0;
29         }
30         if (sum > 100000 || A > 60000 || B > 60000 || C > 60000) flag = 0;
31         if (flag) rec[++recCnt] = sum;
32     }
33     rep(i,1,recCnt) for(int j = Q; j >= rec[i]; j--){
34         dp[j] = max(dp[j],dp[j - rec[i]] + rec[i]);
35     }
36     printf("%.2f\n",dp[Q] / 100.00);
37 }
38 int main(){
39     while (~scanf("%f%d",&q,&N)){
40         if (N) work();
41     }
42     return 0;
43 }
View Code

posted on 2017-09-22 15:37  ACMICPC  阅读(316)  评论(1编辑  收藏  举报