Question DSA-DP-0045
MediumWhat is the output of this code?
def knap(W, wt, val):
d = [0] * (W + 1)
for w, v in zip(wt, val):
for c in range(W, w - 1, -1):
d[c] = max(d[c], d[c - w] + v)
return d[W]
print(knap(7, [1, 3, 4, 5], [1, 4, 5, 7]))
- A.
10
- B.
12
- C.
Sign up free to see the answer and a step-by-step explanation.