Dynamic Programming21 sections · 916 units
Open in Course

Lessons from Red Green Towers

summary

Three things to remember:

1.1. Add dimensions when one index can't describe the situation. Here, level number alone wasn't enough. You also needed to track red blocks used.

2.2. The transition updates multiple indices. Going from level i1i-1 to ii changed both the level AND potentially the red count.

3.3. The answer might be a sum over states. Not just one cell, but all valid cells where constraints are satisfied. The four-step pattern worked exactly the same. You just had more bookkeeping.