Saturday, February 8, 2025

how to pay n cents

How many different ways can you pay n cents using cents, nickels, dimes, quarters, and half-dollars? Let the answer be An. This is the first problem in Problems and Theorems in Analysis I. Let fcoin[n] be a discrete signal that equals 1 when n is a non-negative multiple of the coin, and 0 everywhere else:
Ex. fnickel[-1] = 0, fnickel[1] = 0, fnickel[5] = 1, fnickel[6] = 0, ...
This can be though of as a forward echo, in which the "future" filter taps are not attenuated

 (fcent*fnickel*fdime*fquarter*fhalf-dollar)[n] = An, where * is the convolution operator. This can be computed via dynamic programming. Start with fcent[n] by setting dp[n] = 1 for all 0 ≤ n ≤ 100, then convolve with the next coin signal. This amounts to applying this update rule from n=1 to n=100: dp[n] ← dp[n] + dp[n - coin_value].

If order of payment matters, then the solution is a simple linear recurrence. A= An - 1 + An - 5 + ... + An - 50.

The explanation by Polya, touches on generating functions:

Supposedly, they are useful for enumeration problems, like integer partition. I guess the connection makes sense because polynomial multiplication amounts to convolution. See these notes:

Dynamic programming solutions to equivalent cses problems: