Data Structures & AlgorithmsHardICPC regional · counting DP

Problem: How many ways are there to make change for 100 using coins of 1, 5, 10, 25 and 50 (order does not matter)? Run the code.

Problem: How many ways are there to make change for 100 using coins of 1, 5, 10, 25 and 50 (order does not matter)? Run the code.
ways = [1] + [0] * 100
for c in [1, 5, 10, 25, 50]:
    for v in range(c, 101):
        ways[v] += ways[v - c]
print(ways[100])
What is printed?
  1. A. 242
  2. B. 300
  3. C. 292
  4. D. 256

Correct answer: C. 292

Processing coin types one at a time counts each multiset exactly once. Looping amounts first would count orderings, which gives a far larger number.

More Coding Interview Problems questions

Exams that ask this topic