Question meaning: Chinese question, but pay attention to the single item is a kind of meaning.
Solution: Screen out the invoices that can be reimbursed according to the meaning of the question, and you can do 01 backpack. Input processing is more troublesome.
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 35;
const int maxm = 3000*1000+50;
double sum;
int f[maxm],w[maxn];
int n,V,m;
int work()
{
for (int i = 1; i <= n; i++)
{
for (int v = V; v >= w[i]; v--)
f[v] = max(f[v],f[v-w[i]] +w[i]);
}
return f[V];
}
int main()
{
while(~scanf("%lf %d",&sum,&n)&&n)
{
memset(f,0,sizeof f);
memset(w,0,sizeof w);
for (int i = 1; i <= n; i++)
{
int temp,flag = 0;
char a,b;
double tmp,ta = 0,tb = 0,tc = 0;
int sum1 = 0;
scanf("%d",&temp);
for (int j = 0; j < temp; j++)
{
getchar();
scanf("%c%c%lf",&a,&b,&tmp);
int t4 = (int)(tmp * 100);
if(a >= 'A' && a <= 'C')
{
if(a == 'A' && ta + t4 <= 60000)ta += t4;
else if(a == 'B'&& tb + t4 <= 60000)tb += t4;
else if(a == 'C'&& tc + t4 <= 60000)tc += t4;
else flag = 1;
}
else flag = 1;
}
sum1 = ta + tb + tc;
if(sum1 > 100000 || flag)
{
w[i] = 0;
}
else {
w[i] = sum1;
}
}
sum *= 100;
V = (int)sum;
//printf("%d\n",V);
/*for (int i = 1; i <= n; i++)
printf("%d\n",w[i]);*/
int ans = work();
double money = ans/100.0;
printf("%.2lf\n",money);
}
}