0
点赞
收藏
分享

微信扫一扫

HDU 2602 Bone Collector


题目链接:​​传送门​​​ 题面:

Problem Description

Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …

The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?

HDU 2602 Bone Collector_#include_02

Input

The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.

Output

One integer per line representing the maximum of the total value (this number will be less than 231).

Sample Input

1
5 10
1 2 3 4 5
5 4 3 2 1

Sample Output

14

题目大意

输入多组数据T。你有一个容量为的背包,有许多价值和体积不等的骨头,你要用背包装下他们其中的一些骨头使价值最大。第一行输入骨头数量和背包体积,第二行有个数,是每个骨头的价值,第三行有个数,是每个骨头的体积。输出有行,是你求得的最大价值。


板子啊
01背包

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
int T, n, V, w[A], v[A], f[A];

int main() {
cin >> T;
while (T--) {
memset(f, 0, sizeof f);
cin >> n >> V;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) cin >> w[i];
for (int i = 1; i <= n; i++)
for (int j = V; j >= w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + v[i]);
cout << f[V] << endl;
}
}


举报

相关推荐

0 条评论