码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1963 Investment 完全背包

时间:2015-02-17 23:32:23      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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

poj题目链接:http://poj.org/problem?id=2063

 

完全背包

每过一年就重新做一次完全背包

注意到本钱非常大 不能直接暴力 

看到基金的成本都是1000的倍数(注意它没说本钱什么的也是1000的倍数)

就要灵活对f[]进行处理了 

 

最后一个问题是 f[]应该给多大

第一次我给了1010然后跪了 才发现只是说本金不超过一百万

注意到一个条件 利息不会超过10%

所以1.1^40=45.26

所以应该定到46000以上

 

 

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn = 12;
const int maxm = 101000;

int w[maxn], c[maxn];
int f[maxm];
int ans;
int n, V;

void CompletePack(int cost, int weight)
{
    for(int i = cost; i <= V; i+=1000)
    {
        f[i/1000] = max(f[i/1000], f[(i-cost)/1000] + weight);
        if(f[i/1000] > ans)
            ans = f[i/1000];
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);

    int T;
    scanf("%d", &T);
    while(T--)
    {
        int k;
        scanf("%d%d", &V, &k);

        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d", &c[i], &w[i]);
        }

        for(int i = 0; i < k; i++)
        {
            ans = 0;
            memset(f, 0, sizeof(f));

            for(int j = 0; j < n; j++)
                CompletePack(c[j], w[j]);

            V += ans;
        }

        printf("%d\n", V);
    }

    return 0;
}

 

hdu 1963 Investment 完全背包

标签:

原文地址:http://www.cnblogs.com/dishu/p/4295555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!