Let dp[i][j] = number of paths to cell (i, j).
Base cases:
dp[0][j] = 1 for all j (top row)
dp[i][0] = 1 for all i (left column)
Recurrence: dp[i][j] = dp[i-1][j] + dp[i][j-1].
Answer: dp[m-1][n-1] (bottom-right cell).
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
(DP recurrence)
Let dp[i][j] = number of paths to cell (i, j).
Base cases:
dp[0][j] = 1 for all j (top row)
dp[i][0] = 1 for all i (left column)
Recurrence: dp[i][j] = dp[i-1][j] + dp[i][j-1].
Answer: dp[m-1][n-1] (bottom-right cell).