题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1864
题目很坑!!!
是单类物品不能超出600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double d[30+5];
//前i个最大的报销额
double P[3];
int main()
{
double MaxPrice,price; int N,m;
while(cin>>MaxPrice>>N&&N)
{
memset(d,0,sizeof(d));
for(int i=0;i<N;i++)
{
cin>>m;
double sum=0,p; char type; bool ok=true;
memset(P,0,sizeof(P));
while(m--){
scanf(" %c:%lf",&type,&p);
if(type!='A'&&type!='B'&&type!='C') ok=false;
P[type-'A']+=p;
if(P[type-'A']>600) ok=false;
sum+=p;
}
if(sum>1000) ok=false;
price=ok?sum:0;
for(int j=0;j<=i;j++)
d[j+1]=max(d[j+1],d[j]+price>MaxPrice?d[j]:d[j]+price);
}
printf("%.2f\n",d[N]);
}
return 0;
}