Data Structures & AlgorithmsHardProduct-company placement

How many subsets of {1, 6, 7, 8, 11, 13, 14} have sum exactly 28?

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

Correct answer: D. 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 63.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic