HDU 2602 (简单的01背包) Bone Collector

时间:2021-11-19 15:28:39

很标准的01背包问题

 //#define LOCAL
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = + ;
int w[maxn], v[maxn], dp[maxn]; int main(void)
{
#ifdef LOCAL
freopen("2602in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int n, V;
scanf("%d%d", &n, &V);
for(int i = ; i < n; ++i)
scanf("%d", &w[i]);
for(int i = ; i < n; ++i)
scanf("%d", &v[i]);
memset(dp, , sizeof(dp));
for(int i = ; i < n; ++i)
for(int j = V; j >= v[i]; --j)
dp[j] = max(dp[j], dp[j-v[i]] + w[i]);
printf("%d\n", dp[V]);
}
return ;
}

代码君