01背包
定义dp[i][j]表示从前i件物品中选,体积不超过 j 的最大价值
N, V = map(int, input().split())
v = [0] * (N + 1)
w = [0] * (N + 1)
for i in range(1,N + 1):
v[i],w[i] = map(int,input().split())
f = [[0] * (V + 1) for _ in range(N + 1)]
# 对于第i件物品,选或不选!
for i in range(1, N + 1):
for j in range(V, -1, -1):
if j < v[i]:
f[i][j] = f[i - 1][j]
else:
f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i])
print(f[N][V])
标签:背包,int,range,split,input,DP
From: https://www.cnblogs.com/gebeng/p/18116315