Dynamic Programming21 sections · 916 units
Open in Course

Why One Dimension Fails

The limitation

Imagine counting paths from the top-left corner to the bottom-right corner of a grid. Can dp[steps]dp[steps] = "number of paths after kk steps" work? No. Knowing you took 5 steps tells you nothing about WHERE you are.

You could be at cell (3,2)(3, 2) or (1,4)(1, 4). You need to track both your row and column: dp[r][c]dp[r][c] = "number of paths to reach cell (r,c)(r, c)." Now the state captures everything you need: your exact position in the grid. When one number can't capture the full situation, you add another dimension. This is the core insight of multi-dimensional DP.