Data Structures & AlgorithmsHardGATE CS · Product-company placement

How many subsets of {1, 4, 8, 9, 10, 11, 12} have sum exactly 27?

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

Correct answer: A. 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 73.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic