Skip to content

Commit 3feaa69

Browse files
committed
add some notes
1 parent 3ccc670 commit 3feaa69

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

dynamic_programming/climbing_stairs.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
```
88
You are climbing a stair case. It takes n steps to reach to the top.
99
10-
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
10+
Each time you can either climb 1 or 2 steps.
11+
In how many distinct ways can you climb to the top?
1112
1213
Example
1314
Given an example n=3 , 1+1+1=2+1=1+2=3
@@ -24,7 +25,7 @@ return 3
2425
3. Initialization: f[0]=1,f[1]=1
2526
4. Answer: f[n]
2627

27-
尤其注意状态转移方程的写法,f[i]只可能由两个中间状态转化而来,一个是f[i-1],由f[i-1]到f[i]其方法总数并未增加;另一个是f[i-2],由f[i-2]到f[i]隔了两个台阶,因此有1+1和2两个方法,因此容易写成 f[i]=f[i-1]+f[i-2]+1,但仔细分析后能发现,由f[i-2]到f[i]的中间状态f[i-1]已经被利用过一次,故f[i]=f[i-1]+f[i-2]
28+
尤其注意状态转移方程的写法,f[i]只可能由两个中间状态转化而来,一个是f[i-1],由f[i-1]到f[i]其方法总数并未增加;另一个是f[i-2],由f[i-2]到f[i]隔了两个台阶,因此有1+1和2两个方法,因此容易写成 f[i]=f[i-1]+f[i-2]+1,但仔细分析后能发现,由f[i-2]到f[i]的中间状态f[i-1]已经被利用过一次,故f[i]=f[i-1]+f[i-2]. 使用动规思想解题时需要分清『重叠子状态』, 如果有重复的需要去重。
2829

2930
### C++
3031

0 commit comments

Comments
 (0)