zoukankan      html  css  js  c++  java
  • HDU5410——01背包+完全背包——CRB and His Birthday

    http://acm.hdu.edu.cn/showproblem.php?pid=5410

    /*
    先01背包一下再完全背包一下
    */
    /************************************************
    * Author        :Powatr
    * Created Time  :2015-8-20 19:46:35
    * File Name     :1005_1.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int MAXN = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    
    int a[MAXN], b[MAXN], c[MAXN];
    int dp[MAXN];
    int main(){
        int T;
        int n, m;
        scanf("%d", &T);
        while(T--){
            scanf("%d%d", &m, &n);
            memset(dp, 0, sizeof(dp));
            for(int i = 1; i <= n; i++)
                scanf("%d%d%d", &a[i], &b[i], &c[i]);
            for(int i = 1; i <= n; i++){
                for(int j = m; j >= a[i]; j--)
                    dp[j] = max(dp[j], dp[j-a[i]] + b[i] + c[i]);
                for(int j = a[i]; j <= m; j++)
                    dp[j] = max(dp[j], dp[j-a[i]] + b[i]);
            }
            printf("%d
    ", dp[m]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    构建之法阅读笔记02
    学习进度条
    构建之法阅读笔记01
    c++ 与C的区别
    c++ 菜单动态效果
    c++ 方框中绘制菜单代码
    c++ 绘制方框
    c++ 条件编译
    c++ 预处理和多重替换
    c++ 文件共享打开
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4746144.html
Copyright © 2011-2022 走看看