题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
带备忘录的斐波那契数列递归写法
def fib(n): if n < 1: return 0 memo = [0 for _ in range(n + 1)] return helper(memo, n) def helper(memo, m): if m == 1 or m ==2: return 1 if memo[m] != 0: return memo[m] memo[m] = helper(memo, m - 1) + helper(memo, m - 2) return memo[m] n = int(input()) print(fib(n))