题目链接
点此跳转
代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#define LL long long
#define mem(a, b) memset(a, b, sizeof a)
#define lowbit(x) (-x&x)
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define endl '\n'
#define rev(x) reverse(x.begin(), x.end())
using namespace std;
const int N = 1010;
int n, m;
int w[N], v[N];
int f[N];
void solve() {
int tt;
cin >> tt;
while (tt -- ) {
mem(f, 0);
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> w[i];
for (int i = 1; i <= n; i ++ ) cin >> v[i];
for (int i = 1; i <= n; i ++ ) {
for (int j = m; j >= v[i]; j -- )
f[j] = max(f[j], f[j - v[i]] + w[i]);
}
cout << f[m] << endl;
}
}
int main() {
IOS;
solve();
return 0;
}