Data Structures & AlgorithmsHardGATE CS

How many subsets of {3, 5, 6, 7, 8, 10, 14} have sum exactly 24?

  1. A. 26
  2. B. 5
  3. C. 4
  4. D. 6

Correct answer: B. 5

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic