State

dp[i][j] = # paths to reach (i,j).

Advertisement

State

dp[i][j] = # paths to reach (i,j).

Advertisement

Transition

dp[i][j] = dp[i-1][j] + dp[i][j-1]. Came from up OR left.

Base cases

First row + first column all = 1 (only one way).

Closed form

C(M+N-2, M-1) — pure combinatorics. But DP handles obstacles case.