Dynamic Programming21 sections · 916 units
Open in Course

What Is Multi-Dimensional DP?

Core concept

Multi-dimensional DP (dynamic programming) uses states with two or more parameters. Instead of dp[i]dp[i], you have dp[i][j]dp[i][j] or even dp[i][j][k]dp[i][j][k]. A classic example: counting paths in a grid. You need to track both your row and column to know where you are. One number is not enough. dp[r][c]dp[r][c] stores the number of paths to reach cell (r,c)(r, c).

Each dimension captures one aspect of the problem state. More dimensions mean more information tracked, but also more memory and computation. The skill is identifying which dimensions you need.