Dynamic Programming21 sections · 916 units
Open in Course

Intro

Why multi-dimensional DP

Okay, so you've solved problems where one number describes everything you need. House Robber used dp[i]dp[i] for "best answer up to house ii." Fibonacci used dp[n]dp[n] for "the nn-th number."

But what happens when one number isn't enough? What if you need to track both your position AND something else, like how many items you've picked or how much capacity you've used?

I'll show you how to add dimensions to your DP state. You'll solve Red Green Towers, Grid 1, and Edit Distance. By the end, two-dimensional DP will feel natural.