From the course: Fundamentals of Dynamic Programming

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Breaking down the flowerbox problem into subproblems

Breaking down the flowerbox problem into subproblems - Python Tutorial

From the course: Fundamentals of Dynamic Programming

Breaking down the flowerbox problem into subproblems

- [Instructor] Let's summarize our goal in the flower box problem. We have a flower box with a few places to plant flowers. Each location has nutrients that influence how tall the flower will be. You can't plant flowers next to each other, and we want to maximize the total height of all the planted flowers. In this example the best option is to plant it in locations one and four indexing from zero. In general the greedy approach of picking the most nutrient-dense locations doesn't always work. So what can we do instead? Well, at any given spot, we can choose to plant a flower or not. If we do plant a flower in that spot, the previous spot is now off limits, but you can optimize the rest of the flower box two locations down all the way to the beginning. It doesn't matter where you plant flowers in that segment as it has no effect on the current location. On the other hand we can choose to not plant a flower in the…

Contents