Data Structures & AlgorithmsHardProduct-company placement

How many subsets of {1, 3, 4, 5, 8, 10, 13} have sum exactly 20?

  1. A. 91
  2. B. 3
  3. C. 2
  4. D. 4

Correct answer: B. 3

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic