zoukankan      html  css  js  c++  java
  • hdu 2602 Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602

    裸的01背包

    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <set>
    #include <queue>
    #include <vector>
    
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 1010;
    
    int w[maxn], c[maxn], f[maxn];
    int ans;
    int n, V;
    
    
    void ZeroOnePack(int cost, int weight)
    {
        for(int i = V; i >= cost; i--)
        {
            f[i] = max(f[i], f[i-cost] + weight);
            if(f[i] > ans)
                ans = f[i];
        }
    }
    
    int main()
    {
        //freopen("in.txt", "r", stdin);
    
        int T;
        scanf("%d", &T);
    
        while(T--)
        {
            ans = 0;
            memset(f, 0, sizeof(f));
    
            scanf("%d%d", &n, &V);
    
            for(int i = 0; i < n; i++)
                scanf("%d", &w[i]);
            for(int i = 0; i < n; i++)
                scanf("%d", &c[i]);
    
            for(int i = 0; i < n; i++)
                ZeroOnePack(c[i], w[i]);
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
  • 相关阅读:
    Core Java 5
    pyDay11
    c++第二十一天
    pyDay10
    c++第二十天
    RadioButton控件
    ListBox控件
    Image控件
    FileUpload控件
    DropDownList控件
  • 原文地址:https://www.cnblogs.com/dishu/p/4295557.html
Copyright © 2011-2022 走看看