Data Structures & AlgorithmsHardICPC regional · counting DP

Problem: How many integer partitions does 6 have (unordered sums of positive integers equal to 6)? Run the DP.

Problem: How many integer partitions does 6 have (unordered sums of positive integers equal to 6)? Run the DP.
n = 6
p = [1] + [0] * n
for part in range(1, n + 1):
    for v in range(part, n + 1):
        p[v] += p[v - part]
print(p[n])
What is printed?
  1. A. 10
  2. B. 12
  3. C. 11
  4. D. 15

Correct answer: C. 11

The classic partition numbers are p(6) = 11, found by adding parts in a fixed order so each partition counts once.

More Coding Interview Problems questions

Exams that ask this topic