首页 > 其他 > 详细

hdu 1963 Investment 多重背包

时间:2015-02-20 09:40:29      阅读:214      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963

//多重背包
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1000000 + 10;
#define N 15
long long dp[maxn], ans;
int c[N], w[N], V;
void Pack(int C, int W)
{
    for(int i = C; i < maxn; i++)
        dp[i] = max(dp[i], dp[i-C]+W);
}
int main()
{
    int n, d, y;
    scanf("%d", &n);
    while(n--){
        scanf("%d%d", &V, &y);
        scanf("%d", &d);
        for(int i = 1; i <= d; i++){
            scanf("%d%d", &c[i], &w[i]);
            c[i] /= 1000;
        }
        memset(dp, 0, sizeof(dp));
        ans = V;
        V /= 1000;
        for(int i = 1; i <= d; i++)
            Pack(c[i], w[i]);
        while(y--)
            ans += dp[ans/1000];
        cout << ans << endl;    
    }
    return 0;
}

 

hdu 1963 Investment 多重背包

原文:http://www.cnblogs.com/ACFLOOD/p/4296407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!