hdu1846

http://acm.hdu.edu.cn/submit.php?pid=1864

注意细节

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[4000000];
int c[500];
inline int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    double m1;
    int n;
    while(scanf("%lf%d",&m1,&n),n)
    {
        int i,j;
        int cas=1;
        char str;
        memset(dp,0,sizeof(dp));
        memset(c,0,sizeof(c));
        int m=(int)(m1*100);
        for(i=1;i<=n;i++)
        {
            int k;int ta=0,tb=0,tc=0;
            scanf("%d",&k);
            for(j=0;j<k;j++)
            {
                double t1;

                scanf(" %c:%lf",&str,&t1);
                getchar();
                if(str=='A')
                    ta+=(int)(t1*100);
                else if(str=='B')
                    tb+=(int)(t1*100);
                else if(str=='C')
                    tc+=(int)(t1*100);
                else
                    break;
            }
            if(j==k&&ta<=60000&&tb<=60000&&tc<=60000)
            {
                int t=ta+tb+tc;
                if(t<=100000)
                    c[cas++]=t;
            }
        }
        for(i=1;i<=cas;i++)
        {
            for(j=m;j>=c[i];j--)
                dp[j]=max(dp[j],dp[j-c[i]]+c[i]);
        }
        printf("%.2f\n",(double)dp[m]/100);
    }
    return 0;
}


你可能感兴趣的:(hdu1846)