Data Structures & AlgorithmsVery hardGATE CS

In how many ways can 30 be written as a sum of distinct positive integers, each at most 10, if the order of the summands does not matter?

  1. A. 43
  2. B. 35
  3. C. 3590
  4. D. 39

Correct answer: D. 39

This counts subsets of {1,...,10} with sum 30 (equivalently, by complement in the total 55, sum 25); a subset-sum DP gives 39. Ordinary partitions of 30 into parts at most 10 give 3590, which allow repeated parts.

More Coding Interview Problems questions

Exams that ask this topic