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;
    }
    

      

  • 相关阅读:
    各个控件说明
    html常用
    abp.message
    ABP框架——单表实体流程
    AngularJS $http和$.ajax
    AngularJS ng-if使用
    AngularJS 多级下拉框
    AngularJS 计时器
    AngularJS table循环数据
    Python之待学习记录
  • 原文地址:https://www.cnblogs.com/headboy2002/p/9433887.html
Copyright © 2011-2022 走看看