DynProgChange - The Change Problem "The Change...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The Change Problem "The Change Store" was an old SNL skit (a pretty dumb one. ..) where they would say things like, "You need change for a 20? We'll give you two tens, or a ten and two fives, or four fives, etc." If you are a dorky minded CS 2 student, you might ask yourself (after you ask yourself why those writers get paid so much for writing the crap that they do), "Given a certain amount of money, how many different ways are there to make change for that amount of money?" Let us simplify the problem as follows: Given a positive integer n, how many ways can we make change for n cents using pennies, nickels, dimes and quarters? Recursively, we could break down the problem as follows: To make change for n cents we could: 1) Give the customer a quarter. Then we have to make change for n-25 cents 2) Give the customer a dime. Then we have to make change for n-10 cents 3) Give the customer a nickel. Then we have to make change for n-5 cents 4) Give the customer a penny. Then we have to make change for n-1 cents. If we let T(n) = number of ways to make change for n cents, we get the formula T(n) = T(n-25)+T(n-10)+T(n-5)+T(n-1)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Is there anything wrong with this? If you plug in the initial condition T(1) = 1, T(0)=1, T(n)=0 if n<0, you'll find that the values this formula produces are incorrect. (In particular, for this recurrence relation T(6)=3, but in actuality, we want T(6)=2.) So this can not be right. What is wrong with our logic? In particular, it can been seen that this formula is
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/09/2009.

Page1 / 6

DynProgChange - The Change Problem &quot;The Change...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online