。。。。。
2024-08-18 15:21:41
发布于:广东
7阅读
0回复
0点赞
def max_value(n, m, weights, values):
dp = [0] * (m + 1)
for i in range(n):
weight = weights[i]
value = values[i]
for j in range(m, weight - 1, -1):
dp[j] = max(dp[j], dp[j - weight] + value)
return dp[m]
# 示例输入
n, m = 3, 8
weights = [2, 5, 5]
values = [3, 4, 5]
print(max_value(n, m, weights, values)) # 输出:8
这里空空如也
有帮助,赞一个