zoukankan      html  css  js  c++  java
  • hdu 1963 Investment 完全背包

    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
    ", V);
        }
    
        return 0;
    }
  • 相关阅读:
    [BetterExplained]书写是为了更好的思考
    java 连接 mysql 数据库 ..password [yes]问题
    学习密度与专注力
    抠鼻屎的方法
    张飞流水账(摘)
    用 C 语言 连接 mysql (问题已解决)
    编程的首要原则(s)是什么?
    Tomat源码学习(二)(转载)
    [BetterExplained]为什么你应该(从现在开始就)写博客
    事件 代理 练习
  • 原文地址:https://www.cnblogs.com/dishu/p/4295555.html
Copyright © 2011-2022 走看看