From the course: Fundamentals of Dynamic Programming
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Solving the change-making problem in Python - Python Tutorial
From the course: Fundamentals of Dynamic Programming
Solving the change-making problem in Python
- [Instructor] We solved the change making problem, by first defining a function f of i and t. This function captures the minimum number of coins needed to make target amount using only denominations d zero, up to d I. We also define the recurrence relation and how to extract the final answer from the recurrence relation. Because we don't solve every sub problem in the dependency graph, we decided we would use memoirization to implement the recurrence relation. Let's see how all this translates into Python. In this implementation, I created an inner function to represent the sub problem being solved. That way, I always have access to all the denominations as well as the cash that I can use throughout the execution. As is typical with memorization, we first check if the inputs of the sub-problem are in the cash already. If so, we can just return the cash value. But, if the value is not already cashed, we need to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Planting flowers in a flowerbox1m 56s
-
(Locked)
Breaking down the flowerbox problem into subproblems3m 27s
-
(Locked)
Solving the flowerbox problem in Python1m 19s
-
(Locked)
How many ways can you make change?1m 52s
-
(Locked)
Breaking down the change-making problem into subproblems4m 23s
-
(Locked)
Solving the change-making problem in Python2m 13s
-
-
-
-