hdu_2602

#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

hdu_2602的相关文章

HDU_01背包系列

HDU_2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 49986    Accepted Submission(s): 20965 Problem Description Many years ago , in Teddy's hometown there was a man who was c