Dynamic Programming21 sections · 916 units
Open in Course

Grid 1 - State Definition

What dp[i][j] means

Define dp[i][j]dp[i][j] = number of paths from (1,1)(1,1) to cell (i,j)(i, j). This is clean and intuitive. Each cell stores how many ways you can reach it. The answer is dp[H][W]dp[H][W].

Notice: you don't need to track which path you took. You only care about how many paths reach each cell. The state (i,j)(i, j) is enough because movement is restricted to right and down. No extra information is needed to decide the transitions.