← Quiz: 0/1 Knapsack and Subset Sum: all 10 questions
Quiz: 0/1 Knapsack and Subset Sum · Question 5 of 10
What does this print? (code)
What does this print?
dp = [0] * 7
for c in range(2, 7):
dp[c] = max(dp[c], 5 + dp[c - 2])
print(dp[6])
- A.5
- B.10
- C.0
- D.15
Answer & explanation
Correct answer: 15
The loop goes low to high, so the single item (weight 2, value 5) is reused three times. That is unbounded knapsack behaviour.
Can you get the rest right without peeking?
Take the timed Quiz: 0/1 Knapsack and Subset Sum quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →