# 最大报销额

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

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

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;

double q, mp[maxn], price, dp[maxn], sum;
int n,  m;
char s,c;

int main()
{
while(1) {
scanf("%lf%d", &q, &n);
if(n == 0) break;
int cas = 0;
for(int i = 0; i < n; i++) {
bool flag = false;
scanf("%d", &m);
double inta = 0, intb = 0, intc = 0;
bool f = false;
for(int j = 0; j < m; j++) {
getchar();
scanf("%c%c%lf", &s,&c,&price);
if(s == 'A') inta += price;
else if(s == 'B') intb += price;
else if(s == 'C') intc += price;
else {
f = true;
break;
}
}
if((!f)&&(inta <= 600)&&(intb <= 600)&&(intc <= 600)&&(inta+intb+intc <= 1000)) mp[cas++] = (inta+intb+intc);
}
double maxl = 0.0;
sort(mp, mp+cas);
memset(dp, 0, sizeof(dp));
for(int i = 0; i < cas; i++)
for(int j = n; j > 0; j--)
{
if(dp[j - 1] + mp[i] <= q)
dp[j] = max(dp[j], (dp[j - 1] + mp[i]));
maxl = max(maxl, dp[j]);
}
//cout << maxl << endl;
printf("%.2lf\n", maxl);
}
return 0;
}