//注意将价格转化为整数即可 # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int max(int a,int b) { return a>b?a:b; } int dp[3000050]; int main() { int n,i,j,flag,l,m; int suma,sumb,sumc,sum; double q,p; int cot[35]; char c; while(~scanf("%lf%d",&q,&n),n) { l=0; sum=int(q*100); memset(cot,0,sizeof(cot)); for(i=0;i<n;i++) { scanf("%d",&m); suma=0; sumb=0; sumc=0; flag=1; for(j=0;j<m;j++) { scanf(" %c:%lf",&c,&p); { int p1=int(p*100); if(c=='A'&&suma+p1<=60000) suma+=p1; else if(c=='B'&&sumb+p1<=60000) sumb+=p1; else if(c=='C'&&sumc+p1<=60000) sumc+=p1; else flag=0; } } if(flag&&suma+sumb+sumc<=100000) cot[l++]=suma+sumb+sumc; } memset(dp,0,sizeof(dp)); for(i=0;i<l;i++) { for(j=sum;j>=cot[i];j--) dp[j]=max(dp[j],dp[j-cot[i]]+cot[i]); } printf("%.2lf\n",dp[sum]/100.0); } return 0; }
时间: 2024-11-10 20:50:07