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\n",dp[V]);
    }
    return 0;
}

 

posted @ 2015-07-14 18:30  Fighting_Heart  阅读(110)  评论(0编辑  收藏  举报