zoukankan      html  css  js  c++  java
  • luogu1064 金明的预算方案

      这道题我就想说一点:审题!附件只有2个!钱是10的整数倍,不是100的整数倍!

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    const int MAX_OBJ = 60, MAX_V = 5000, MINF = 0xcfcfcfcf;
    int ObjCnt[MAX_OBJ], V[MAX_OBJ][5], W[MAX_OBJ][5];
    int F[MAX_V];
    int TotV, TotObj;
    
    int Dp()
    {
        memset(F, MINF, sizeof(F));
        F[0] = 0;
        for (int i = 1; i <= TotObj; i++)
            for (int j = TotV; j >= 0; j--)
                for (int k = 1; k <= ObjCnt[i]; k++)
                    if (V[i][k] <= j)
                        F[j] = max(F[j], F[j - V[i][k]] + W[i][k]);
        int ans = 0;
        for (int j = 1; j <= TotV; j++)
            ans = max(ans, F[j]);
        return ans;
    }
    
    int main()
    {
        scanf("%d%d", &TotV, &TotObj);
        for (int i = 1; i <= TotObj; i++)
            ObjCnt[i] = 1;
        TotV /= 10;
        for (int i = 1; i <= TotObj; i++)
        {
            int v, w, group;
            scanf("%d%d%d", &v, &w, &group);
            v /= 10;
            if (group == 0)
            {
                V[i][1] = v;
                W[i][1] = w * v;
            }
            else
            {
                ObjCnt[group]++;
                V[group][ObjCnt[group]] = v;
                W[group][ObjCnt[group]] = w * v;
            }
        }
        for (int i = 1; i <= TotObj; i++)
        {
            if (ObjCnt[i] == 1 && !V[i][1])
                ObjCnt[i] = 0;
            else if (ObjCnt[i] == 2)
            {
                V[i][2] += V[i][1];
                W[i][2] += W[i][1];
            }
            else if (ObjCnt[i] == 3)
            {
                ObjCnt[i]++;
                V[i][4] = V[i][1] + V[i][2] + V[i][3];
                W[i][4] = W[i][1] + W[i][2] + W[i][3];
                V[i][2] += V[i][1];
                W[i][2] += W[i][1];
                V[i][3] += V[i][1];
                W[i][3] += W[i][1];
            }
        }
        printf("%d
    ", Dp() * 10);
        return 0;
    }
    

      

  • 相关阅读:
    二十三、Android源代码是这样搞到的(图解)
    defer用途
    vscode中go插件配置
    peewee外键性能问题
    bootstrap-select属性
    go环境变量及build文件
    peewee在flask中的配置
    python元类
    Java静态方法、单例模式区别
    Java实现list清除重复的字符串
  • 原文地址:https://www.cnblogs.com/headboy2002/p/9433887.html
Copyright © 2011-2022 走看看