Data Structures & AlgorithmsHardGATE CS

How many subsets of {4, 7, 9, 10, 11, 13, 14} have sum exactly 31?

  1. A. 17
  2. B. 3
  3. C. 5
  4. D. 4

Correct answer: D. 4

dp[s] counts subsets with sum s; for each element update s from HIGH to low so it is used at most once, giving 4. Updating low to high lets an element be reused and gives 17.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic