I know the algorithm to solve the coin change problem for infinite number of denominations but is there any algorithm for finite number of denominations using DP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. Modify the initial algorithm such that, when it’s about to add a coin that would exceed the number of available coins of that denomination, it doesn’t, instead. Then it will only print the valid combos.
Another, more simple way is: run the algorithm without bounds, then filter the output based on what combinations are invalid. Thinking of it this way makes it really obvious that the problem is indeed solvable.