# 最大报销额

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

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

http://acm.hdu.edu.cn/showproblem.php?pid=1864

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[3000005], value[35];
int n, v, m, Count;
double f, suma, sumb, sumc, sumother, money;
void caculator() {
int i, j;
memset(dp, 0, sizeof(dp));
for(i = 0; i < Count; i++)
for(j = v; j >= value[i]; j--) {       //价值和所占权重都是每个账单的金额
dp[j] = max(dp[j], dp[j-value[i]] + value[i]);
}
printf("%.2lf\n", dp[v]/100.0);
}
int main() {
int i, j;
char c1, c2;
while(scanf("%lf%d", &f, &n) != EOF) {
if(n == 0)
return 0;
f = f * 100;
v = (int)f;
Count = 0;
for(i = 1; i <= n; i++) {
scanf("%d", &m);
suma = sumb = sumc = sumother = 0.0;
for(j = 1; j <= m; j++) {               //用来处理每个账单
getchar();
scanf("%c%c%lf", &c1, &c2, &f);
switch(c1) {                    //suma, sumb, sumc, sumother,
case 'A':suma += f;break;   //记录A B C类和其他类的金额
case 'B':sumb += f;break;
case 'C':sumc += f;break;
default:sumother += f;break;
}
}   //当满足以下条件时，才能存储到value数组，用来进行dp
if(sumother <= 0.0 && suma <= 600.0 && sumb <= 600.0 && sumc <= 600.0 && suma + sumb + sumc <= 1000.0)
value[Count++] = (int)((suma + sumb + sumc)*100);
}
caculator();
}
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120