zoukankan      html  css  js  c++  java
  • [DP] [01背包] [洛谷] P1060 开心的金明

    基础01背包练习

    value of j[i] equal to vj[i] * wj[i]

    #pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    
    const int MAXN = 1e6 + 10;
    
    int dp[MAXN] = {0}, volume[MAXN] = {0}, value[MAXN] = {0};
    
    int main()
    {
        ios::sync_with_stdio(false);
    
        cin.tie(0);     cout.tie(0);
    
        int len, sumvolume;
        
        cin>>sumvolume>>len;
        
        for(int i = 1; i <= len; i++)
        {
            int tmp;
            cin>>volume[i]>>tmp;
            value[i] = volume[i] * tmp;
        }
        
        for(int i = 1; i <= len; i++)
        {
            for(int j = sumvolume; j >= volume[i]; j--)
            {
                dp[j] = max(dp[j], dp[j - volume[i]] + value[i] );
            }
        }
            
        cout<<dp[sumvolume]<<endl;
    
        return 0;
    }
    
  • 相关阅读:
    mysql主从复制
    gitlab安装
    nginx新加模块编译
    flask编写prometheus采集指标脚本
    powerdns的安装
    grafana中prometheus的查询语句
    python编写prometheus的监控指标
    maven常用命令参数
    flask架构中的方法学习
    Java命名规范
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270494.html
Copyright © 2011-2022 走看看