Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

In how many ways can 12 be written as a sum of DISTINCT positive integers, where order does not matter (so 12 itself counts as one way)?

  1. A. 77
  2. B. 15
  3. C. 16
  4. D. 12

Correct answer: B. 15

Use 0/1-knapsack style counting: iterate the item sizes and process the target downwards so each size is used at most once. Iterating upwards (as in the unbounded coin-change count) allows repeated parts and gives the larger count.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic