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
123.50 1000.00 1200.50
#include<cstdio> #include<cstring> using namespace std; #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) int dp[3000005]; int num[35]; int main() { int n,a,b,c,t; char s[5]; double temp,m; for(;scanf("%lf%d",&m,&n),n;) { int cnt=0; for(int i=0;i<n;++i) { bool flag=false; a=b=c=0; scanf("%d",&t); for(;t--;) { scanf("%1s:%lf",s,&temp); switch(s[0]) { case 'A':a+=(int)(temp*100); break; case 'B':b+=(int)(temp*100); break; case 'C':c+=(int)(temp*100); break; default: flag=true; break; } } //判断发票能否报销 if(flag) continue; if(a<=60000&&b<=60000&c<=60000&&(a+b+c)<=100000) num[cnt++]=(a+b+c); } memset(dp,0,sizeof(dp)); int summ=0,maxx=0; for(int i=0;i<cnt;++i) summ+=num[i]; //01背包计算 for(int i=0;i<cnt;++i) for(int j=min((int)(m*100),summ);j>=num[i];--j) { dp[j]=max(dp[j],dp[j-num[i]]+num[i]); maxx=max(maxx,dp[j]); } printf("%.2f\n",(double)(maxx)/100); } return 0; }来源: http://blog.csdn.net/ACM_Ted