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?- A. 242
- B. 300
- C. 292
- 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
- Problem: Find the longest palindromic substring length of 'forgeeksskeegfor' by expanding around each centre. python s =…
- Problem: What does the following print? It counts distinct values in each window of size 3. python from collections import Counter a = [1…
- Problem: Rotate the array [1, 2, 3, 4, 5, 6, 7] to the right by k = 3 using the three-reversal method. What is printed? python a = [1, 2…
- Problem: How many unordered pairs of distinct elements of [1, 5, 3, 9, 7, 2] have absolute difference exactly 2? Run the code. python a =…
- Problem: Minimum cost to climb stairs where cost[i] is paid when standing on step i and you may take one or two steps. Starting positions…
- Problem: Houses in a circle hold the amounts [2, 3, 2]. You may not rob two adjacent houses, and the first and last are adjacent. Run the…