My mother was posed a question that read roughly as "How many ways are there to make change for a dollar?" The only coins are the penny, nickel, dime, and quarter. Others working with her used the good old pencil and paper approach and tried listing all combinations. Here is a much simpler way that can avoid a lot of the work. It is based on a computer science technique known as "linear programming."
At each step, keep track of how many ways there are to make change for each amount up to 100. (100 cents to a dollar). Start with the quarter. 0 : 1 25 : 1 50 : 1 75 : 1 100 : 1
Now, go through with the dime. For each entry above, add that quantity to monetary amount 10 cents greater. (Ie, that larger quantity can be obtained in the same number of ways as the entry being considered by just adding a dime.) It is important to start with "0" cents and work your way up.
Note that the numbers are building up rapidly. The next step would be to do the same to pennies. Luckily, this isn't actually necessary. The number of ways to reach 100 is the sum of all of those (since any way you can reach, say, 45, can be made into a unique combination of 100 by adding 55 pennies.) Thus, in general, you can find out the solution for ANY number 1-100 by adding up the numbers less or equal to it.
Thus, there are 242 combinations. I did tremendously less work than I would have enumerating all combinations. I have used this technique to treat quantities as high as a million dollars (using a computer of course). This would have been impossible had I tried listing all combinations.
�Change� problems are classic in combinatorial mathematics. Using this generating polynomial, . we find that the coefficient of x100 is indeed 242. The coefficient of x53 is 49, so there are 49 ways to make 53cents using pennies, nickels, dimes and quarters. Using MathCad or StudyWorks we can collect the coefficients of the polynomial.May I suggest a wonderful little book: Mathematics of Choice by Ivan Niven. The book is part of The Mathematical Association of America, New Mathematical Library.
I have seen the polynomial before. However, it is really just a fancy way of rewriting the original problem. Expanding it is also no easier to calculate than the original problem. Substituting a "sufficiently large" value for x is even worse. I see no way the use of such a polynomial can aid in computation by humans or by computers. A closed form solution, however, would be interesting to see. Tests suggest such a formula probably exists. For powers of ten, an obvious pattern emerges after the first vew powers.
The simple method illustrated initially takes O(r n) steps, where "r" is the number of coins and "n" is the number of cents for which change is sought. Moreover, the results for all amounts of change up to n can be obtained at the same time at no additional cost.
If "x" is replaced by a constant with "b" bits (or digits), and multiplication is performed, O(r n b log(n b)) is a fair estimate.
Expanding the polynomial (using convolution and FFT) would be about O(r n log n). Retrieving only the coefficient needed would take O(r n) as well, but the constant would be a bit larger.
Note: O(n^2), for example, means that the time required to compute grows no faster than the square of the size of the input. If the input doubles, the time required might quadruple.
The nice part about a closed form solution is that the output may be calculated very quickly.