Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 29 Accepted Submission(s) : 11
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; double dp[40],money[40]; int main(){ //freopen("input.txt","r",stdin); double Q,a,b,c; int n; while(~scanf("%lf%d",&Q,&n) && n){ memset(money,0,sizeof(money)); int cnt=0,k; char ch; double num; for(int i=0;i<n;i++){ scanf("%d",&k); int flag=1; a=b=c=0; for(int j=0;j<k;j++){ getchar(); scanf("%c:%lf",&ch,&num); if(num>600) flag=0; if(flag){ if(ch=='A') a+=num; else if(ch=='B') b+=num; else if(ch=='C') c+=num; else flag=0; } } if(flag && a<=600 && b<=600 && c<=600 && (a+b+c)<=1000){ money[cnt++]=a+b+c; } } memset(dp,0,sizeof(dp)); for(int i=0;i<cnt;i++) for(int j=cnt;j>=1;j--) if((dp[j-1]+money[i]<=Q)) //改成这样可优化时间 if(j==1 || (dp[j-1]>0 && dp[j-1]+money[i]<=Q)) dp[j]=max(dp[j],dp[j-1]+money[i]); double ans=0; for(int i=0;i<=cnt;i++) if(ans<dp[i]) ans=dp[i]; printf("%.2lf\n",ans); } return 0; }