• 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;
    }
  • 相关阅读:
    lua中for循环
    调试经验
    vim中如何替换
    ~=
    size函数
    ubuntu截屏
    linux下报错处理经验
    error: &#39;Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2)&#39;
    《JavaScript》——DOM
    iOS_截屏并裁剪
  • 原文地址:https://www.cnblogs.com/dishu/p/4295555.html
Copyright © 2020-2023  润新知