Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE

0/1 knapsack, capacity 11. Items (weight, value): (4, 6), (1, 7), (6, 3), (2, 2). What is the maximum total value?

  1. A. 16
  2. B. 18
  3. C. 10
  4. D. 15

Correct answer: A. 16

The DP table dp[i][c] = max(dp[i−1][c], dp[i−1][c−w]+v) over all items and capacities finds the true optimum, 16. A greedy choice by value/weight ratio instead gives 15, which can be suboptimal in 0/1 knapsack because items can't be split.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic