对满足条件的发票做一遍\(01\)背包即可。
const int N = 3e6 + 10;
int f[N];
int n;
double m;
void update(int v)
{
for(int j = m; j >= v; j--)
f[j] = max(f[j], f[j - v] + v);
}
int main()
{
while(cin >> m >> n && n)
{
memset(f, 0 ,sizeof f);
m *= 100;
for(int i = 1; i <= n; i++)
{
int k;
cin >> k;
int sum = 0;
bool ok = true;
int v[3] = {0};
while(k--)
{
char c;
double value;
scanf(" %c:%lf", &c, &value);
value *= 100;
if(c != ‘A‘ && c != ‘B‘ && c != ‘C‘) ok = false;
else v[c - ‘A‘] += value;
sum += value;
if(v[c - ‘A‘] > 60000 || sum > 100000) ok = false;
}
if(ok) update(sum);
}
printf("%.2f\n", f[int(m)] / 100.0);
}
//system("pause");
return 0;
}