HDU 2602 Bone Collector 背包问题

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

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<iomanip>

using namespace std;
const int maxn=100000;

int m[maxn];
int v[maxn];
int dp[maxn];

int main(){
    int T; cin>>T;
    while(T--){
        int n,V; cin>>n>>V;
        for(int i=0;i<n;++i)cin>>m[i];
        for(int i=0;i<n;++i)cin>>v[i];
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;++i)
            for(int j=V;j>=v[i];--j)
                if(dp[j]<dp[j-v[i]]+m[i])
                    dp[j]=dp[j-v[i]]+m[i];
        cout<<dp[V]<<endl;
    }
    return 0;
}


原文地址:https://www.cnblogs.com/javawebsoa/p/3031625.html