UVa12563- Jin Ge Jin Qu hao

思路一定要清晰!

/*
 * Author:  Bingo
 * Created Time:  2014/12/25 3:45:35
 * File Name: uva12563.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
const int maxint = -1u>>1;

int main()
{
    int T;
    int c=1;
    cin>>T;
    while(T--){
        int n,time;
        cin>>n>>time;
        int f[n+1][180*n+700];
        int anss[n+1][180*n+700];
        memset(anss,0,sizeof(anss));
        memset(f,0,sizeof(f));
        int v;
        for (int i=1;i<=n;i++){
            scanf("%d",&v);
            for (int j=0;j<=time-1;j++){
                f[i][j]=(i==1?0:f[i-1][j]);
                anss[i][j]=(i==1?0:anss[i-1][j]);
                if (j>=v)if (f[i][j]<=f[i-1][j-v]+1){
                    if (f[i][j]==f[i-1][j-v]+1) anss[i][j]=max(anss[i][j],anss[i-1][j-v]+v);
                    else anss[i][j]=anss[i-1][j-v]+v;
                    f[i][j]=f[i-1][j-v]+1;
                }
            }
        }
        cout<<"Case "<<c<<": ";
        c++;

        cout<<f[n][time-1]+1<<" "<<anss[n][time-1]+678<<endl;
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/acbingo/p/4183808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值