描述
该题来自于力扣第62题
分析
最经典也最基础的动态规划题了,用dp[i][j]
表示到达i,j
这个网格的步数,这有转移方程
\[
dp[i][j] = \left\{ \begin{aligned} & 1 & i == 0\text{ or }j
== 0 \\ & dp[i-1][j] + dp[i][j-1] & others \end{aligned}\right.
\]
即步数总是等于到达相邻的上方与左方的步数之和。
代码
python
1 | class Solution: |