zoukankan      html  css  js  c++  java
  • 解题报告:hdu2602 Bone collector 01背包模板

    2017-09-03 15:42:20

    writer:pprp

    01背包裸题,直接用一维阵列的做法就可以了

    /*
    @theme: 01 背包问题 - 一维阵列 hdu 2602
    @writer:pprp
    @begin:15:34
    @end:15:42
    @declare:最基本的01背包问题 POJ 3624
    @error:最后取得是dp[M]不是 dp[M-1],然后注意数据范围dp的数据范围是M的范围
    @date:2017/9/3
    */
    
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    const int maxn = 1010;
    int dp[maxn];
    int w[maxn], v[maxn];
    int N, M;
    
    int main()
    {
        freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false);
        int cas;
        cin >> cas;
        while(cas--)
        {
            memset(dp,0,sizeof(dp));
            cin >> N >> M;
            for(int i = 0 ; i < N ; i++)
                cin >> v[i];
            for(int i = 0 ; i < N ; i++)
                cin >> w[i];
    
            for(int i = 0 ; i < N ; i++)
            {
                for(int j = M ; j >= w[i] ; j--)
                {
                    dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
                }
            }
            cout << dp[M] << endl;
        }
    
        return 0;
    }

     

  • 相关阅读:
    bzoj3832
    bzoj2117
    bzoj1095
    BZOJ 4247: 挂饰 题解
    1296: [SCOI2009]粉刷匠
    3163: [Heoi2013]Eden的新背包问题
    2287: 【POJ Challenge】消失之物
    1334: [Baltic2008]Elect
    2748: [HAOI2012]音量调节
    1606: [Usaco2008 Dec]Hay For Sale 购买干草
  • 原文地址:https://www.cnblogs.com/pprp/p/7469729.html
Copyright © 2011-2022 走看看