Update 10.1 斐波那契数列.md

重新绘制配图。
This commit is contained in:
CyC2018
2026-10-28 22:51:11 +08:00
parent fa135fe1a9
commit a6b4bd07d8
3 changed files with 2 additions and 2 deletions
+2 -2
View File
@@ -8,13 +8,13 @@
写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项。答案需要取模 1e9+7(1000000007)。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/45be9587-6069-4ab7-b9ac-840db1a53744.jpg" width="330px"> </div><br>
<div align="center"> <img src="pics/fib-formula.png" width="420px"/> </div><br>
## 解题思路
如果使用递归求解,会重复计算一些子问题。例如,计算 f(4) 需要计算 f(3) 和 f(2),计算 f(3) 需要计算 f(2) 和 f(1),可以看到 f(2) 被重复计算了。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c13e2a3d-b01c-4a08-a69b-db2c4e821e09.png" width="350px"/> </div><br>
<div align="center"> <img src="pics/fib-recursion-tree.png" width="500px"/> </div><br>
递归是将一个问题划分成多个子问题求解,动态规划也是如此,但是动态规划会把子问题的解缓存起来,从而避免重复求解子问题。
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB