http://acm.hdu.edu.cn/showproblem.php?pid=1864
01背包 主要是把价值转化为整形,*100即可 = =!
#include <queue>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
double Q;
int N,QQ;
struct pro{
char name;
double key;
};
int sum[35],dp[3000010];
void onezeropack(){
memset(dp, 0, sizeof(dp));
for(int i=0; i<N; i++){
for(int j=QQ; j>=sum[i]; j--){
dp[j] = max(dp[j], dp[j - sum[i]] + sum[i]);
}
}
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%lf%d",&Q, &N) != EOF){
if(!N) break;
else{
QQ = Q * 100;
memset(sum, 0, sizeof(sum));
for(int i=0; i<N; i++){
int M;
pro tmp;
scanf("%d",&M);
bool flag = true;
int a = 0, b = 0, c = 0;
for(int j=0; j<M; j++){
getchar();
scanf("%c:%lf",&tmp.name,&tmp.key);
tmp.key *= 100;
if(tmp.name == 'A')
a += tmp.key;
else if(tmp.name == 'B')
b += tmp.key;
else if(tmp.name == 'C')
c += tmp.key;
else flag = false;
}
if(a > 60000 || b > 60000 || c > 60000) flag = false;
if(a + b + c > 100000) flag = false;
if(flag) sum[i] = a+b+c;
}
onezeropack();
double ans = (double)dp[QQ]/100;
printf("%.2lf\n",ans);
}
}
return 0;
}