1 5 10 1 2 3 4 5 5 4 3 2 1
14
/*=============================================================================
#
# Author: liangshu - cbam
#
# QQ : 756029571
#
# School : 哈尔滨理工大学
#
# Last modified: 2015-08-28 19:18
#
# Filename: B.cpp
#
# Description:
# The people who are crazy enough to think they can change the world, are the ones who do !
=============================================================================*/
#
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
struct A
{
int val, v;
}E[1011];
int main(){
int T;
int dp[1011];
cin>>T;
int n, v;
while(T--){
scanf("%d%d",&n, &v);
for(int i = 1; i <= n; i++){
scanf("%d",&E[i].val);
}
for(int i = 1; i <= n; i++){
scanf("%d",&E[i].v);
}
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= n; i++){
for(int V = v; V >= E[i].v; V--){
dp[V] = max(dp[V], dp[V - E[i].v] + E[i].val);
}
}
printf("%d\n",dp[v]);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
杭电 HDU ACM Bone Collector (dp 01)
原文地址:http://blog.csdn.net/lsgqjh/article/details/48056515