Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement

Items as (weight, value) are [(3, 5), (4, 6), (5, 9), (7, 13), (2, 8)]. Each item can be used at most once. What is the maximum value of a selection whose total weight is EXACTLY 8?

  1. A. 17
  2. B. 21
  3. C. 14
  4. D. 13

Correct answer: C. 14

Initialise dp[0] = 0 and every other dp[c] = −∞, so only exact sums are reachable. Using dp[c] = 0 for all c answers 'weight at most 12', which may leave capacity unused.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic