/*
* 01背包裸题
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 1001
#define MAXV 1001
int val[MAXN], vol[MAXN], dp[MAXV];
int zero_one_package(int n, int max_v)
{
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i ++) {
for(int v = max_v; v >= vol[i]; v --) {
dp[v] = max(dp[v], dp[v-vol[i]]+val[i]);
}
}
return dp[max_v];
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n, v, cas;
scanf("%d", &cas);
while( cas -- ) {
scanf("%d %d", &n, &v);
for(int i = 0; i < n; i ++) {
scanf("%d", &val[i]);
}
for(int i = 0; i < n; i ++) {
scanf("%d", &vol[i]);
}
printf("%d\n", zero_one_package(n, v));
}
return 0;
}
hdu_2602
最新推荐文章于 2021-01-18 14:47:36 发布