Question DSA-DP-0016
HardWhat is the output of this code?
items, W = [(1, 1), (3, 4), (4, 5), (5, 7)], 7
dp = [0] * (W + 1)
for w, v in items:
for c in range(W, w - 1, -1):
dp[c] = max(dp[c], dp[c - w] + v)
print(dp[W])
- A.
10
- B.
7
- C.
Sign up free to see the answer and a step-by-step explanation.