diff --git a/notes/10.1 斐波那契数列.md b/notes/10.1 斐波那契数列.md index 21101ff0..57389b04 100644 --- a/notes/10.1 斐波那契数列.md +++ b/notes/10.1 斐波那契数列.md @@ -8,13 +8,13 @@ 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项。答案需要取模 1e9+7(1000000007)。 -

+

## 解题思路 如果使用递归求解,会重复计算一些子问题。例如,计算 f(4) 需要计算 f(3) 和 f(2),计算 f(3) 需要计算 f(2) 和 f(1),可以看到 f(2) 被重复计算了。 -

+

递归是将一个问题划分成多个子问题求解,动态规划也是如此,但是动态规划会把子问题的解缓存起来,从而避免重复求解子问题。 diff --git a/notes/pics/fib-formula.png b/notes/pics/fib-formula.png new file mode 100644 index 00000000..b3ac6bd8 Binary files /dev/null and b/notes/pics/fib-formula.png differ diff --git a/notes/pics/fib-recursion-tree.png b/notes/pics/fib-recursion-tree.png new file mode 100644 index 00000000..8dec60ce Binary files /dev/null and b/notes/pics/fib-recursion-tree.png differ