Add dp
This commit is contained in:
parent
59242266b3
commit
65c6c74cc4
@ -51,6 +51,11 @@
|
||||
|
||||
- [总结](./greedy.md)
|
||||
|
||||
# 动态规划
|
||||
|
||||
- [总结](./dynamic-programming.md)
|
||||
- [基础问题](./dynamic-programming-basic.md)
|
||||
|
||||
# STL
|
||||
|
||||
- [总结](./stl.md)
|
||||
|
12
notes/src/dynamic-programming-basic.md
Normal file
12
notes/src/dynamic-programming-basic.md
Normal file
@ -0,0 +1,12 @@
|
||||
# 基础问题
|
||||
|
||||
## [509. 斐波那契数](https://leetcode.cn/problems/fibonacci-number/)
|
||||
|
||||
1. `dp[i]` 是第 `i` 个斐波那契数的数值
|
||||
2. `dp[i] = dp[i - 1] + dp[i - 2]`
|
||||
3. `dp[0] = 0`, `dp[1] = 1`
|
||||
4. 从前向后遍历
|
||||
|
||||
```cpp
|
||||
|
||||
```
|
11
notes/src/dynamic-programming.md
Normal file
11
notes/src/dynamic-programming.md
Normal file
@ -0,0 +1,11 @@
|
||||
# 总结
|
||||
|
||||
和贪心相似,从将问题划分为多个子问题,最后得出最终问题的解,但是区别在于每一步之间涉及到状态推导,下一步是基于上一步的结果和之前的记忆(也就是上上次,上上上次等的结果)经过一定逻辑推导得出的。
|
||||
|
||||
分五步:
|
||||
|
||||
1. 确定 `dp[i]` 是什么
|
||||
2. 确定递推公式
|
||||
3. `dp` 数组如何初始化
|
||||
4. 确定遍历顺序(从前向后还是从后向前)
|
||||
5. 推几个来验证
|
Loading…
Reference in New Issue
Block a user