zoukankan      html  css  js  c++  java
  • poj2063

    完全背包

    View Code
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    using namespace std;
    
    #define maxm 50005
    #define maxn 15
    
    int n, m, y;
    int weight[maxn], value[maxn];
    int f[maxm];
    
    void input()
    {
        scanf("%d%d", &m, &y);
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
        {
            scanf("%d%d", &weight[i], &value[i]);
            weight[i] /= 1000;
        }
    }
    
    int work()
    {
        double x = m;
        for (int i = 0; i < y; i++)
            x *= 1.1;
        int temp = ceil(x) / 1000 + 2;
        memset(f, 0, sizeof(f));
        for (int i = 0; i < n; i++)
            for (int j = weight[i]; j <= temp; j++)
                f[j] = max(f[j], f[j - weight[i]] + value[i]);
        int ret = m;
        for (int i = 0; i < y; i++)
            ret = ret + f[ret / 1000];
        return ret;
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        int t;
        scanf("%d", &t);
        while (t--)
        {
            input();
            printf("%d\n", work());
        }
        return 0;
    }
  • 相关阅读:
    Animation
    Calendar
    ToggleButton
    ASP.NET备份恢复SqlServer数据库
    ConfirmButton
    DropDown
    备份与恢复ACCESS数据库
    PopupControl
    CascadingDropDown
    RoundedCorners
  • 原文地址:https://www.cnblogs.com/rainydays/p/2585163.html
Copyright © 2011-2022 走看看