UVA 12563(p274)----Jin Ge Jin Qu [h]ao

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=10000;
struct point
{
    int num,time;
    bool operator <(const point &rhs) const
    {
        return num<rhs.num||(num==rhs.num&&time<rhs.time);
    }
};
point d[maxn];
int a[maxn];
int main()
{
    int t,n,T,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        memset(d,0,sizeof(d));
        int sum=0,max_t;
        scanf("%d%d",&n,&T);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        max_t=min(T-1,sum);
        for(int i=0; i<n; i++)
            for(int j=max_t; j>=a[i]; j--)
            {
                point tmp;
                tmp.num=d[j-a[i]].num+1;
                tmp.time=d[j-a[i]].time+a[i];
                if(d[j]<tmp)
                    d[j]=tmp;
            }
        printf("Case %d: %d %d\n",++cas,d[max_t].num+1,d[max_t].time+678);
    }
    return 0;
}

你可能感兴趣的:(UVA 12563(p274)----Jin Ge Jin Qu [h]ao)