#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 1111 int T, N, V, value[MAXN], cost[MAXN], dp[MAXN]; // dp[i] 代表 背包剩余体积为i的时候,已有价值为dp[i] int main(int argc, char const *argv[]) { // freopen("in", "r", stdin); scanf("%d", &T); while(T--){ scanf("%d%d", &N, &V); for(int i = 1; i <= N; ++i) scanf("%d", value+i); for(int i = 1; i <= N; ++i) scanf("%d",cost+i); memset(dp, 0, sizeof(dp)); // for(int i = 1; i <= N; ++i) for(int j = V; j >= cost[i]; --j) dp[j] = std::max(dp[j], dp[j - cost[i]] + value[i]); printf("%d\n", dp[V]); } return 0; }
时间: 2024-10-11 00:13:35