Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

A binary partition of 20 is a way to write 20 as a sum of powers of two (1, 2, 4, 8, ...), where order does not matter and repeats are allowed. How many binary partitions does 20 have?

  1. A. 627
  2. B. 64
  3. C. 46
  4. D. 60

Correct answer: D. 60

Use the coin-change count restricted to coins that are powers of two (outer loop over the powers of two, inner loop ascending). Using all integers as parts counts ordinary partitions, which is a larger number.

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

Exams that ask this topic