HDU 2602 Bone Collector

简单0-1背包

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int N,V;
const int maxn=1000+10;
int dp[maxn],cost[maxn],value[maxn];

int main()
{
    int i,j,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&N,&V); 
        for(i=1; i<=N; i++) scanf("%d",&value[i]);
        for(i=1; i<=N; i++) scanf("%d",&cost[i]);
        memset(dp,0,sizeof(dp));
        for(i=1; i<=N; i++)
            for(j=V; j>=cost[i]; j--)
                dp[j]=max(dp[j],dp[j-cost[i]]+value[i]);
        printf("%d
",dp[V]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/4646295.html