# 最大报销额

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

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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
double v[31];
double dp[31];//以发票数作为背包容量
int main()
{
double pc,a,b,c,tp,maxn;
int n,tn,i,j,lt,flag;
char tc;
while(scanf("%lf %d",&pc,&n)!=EOF&&n!=0)
{
memset(v,0,sizeof(v));
memset(dp,0,sizeof(dp));
lt=1;
while(n--)
{
scanf("%d",&tn);
a=b=c=0;
flag=0;
for(j=0;j<tn;j++)
{
getchar();
scanf("%c:%lf",&tc,&tp);
if(tc=='A'){
a+=tp;
}
else if(tc=='B'){
b+=tp;
}
else if(tc=='C'){
c+=tp;
}
else flag=1;
}
if(!flag&&a<=600&&b<=600&&c<=600&&(a+b+c)<=1000)
v[lt++]=a+b+c;
}
for(i=1;i<lt;i++)
for(j=i-1;j>=0;j--)
{
if(dp[j]+v[i]<=pc)
dp[i]=max(dp[i],dp[j]+v[i]);
}
maxn=0;
for(i=1;i<lt;i++)
{
if(maxn<dp[i])
maxn=dp[i];
}
printf("%.2lf\n",maxn);
}
}