标签:
#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; }
标签:
原文地址:http://www.cnblogs.com/takeoffyoung/p/4295094.html