当前位置:网站首页>HJ37 统计每个月兔子的总数 斐波那契数列
HJ37 统计每个月兔子的总数 斐波那契数列
2022-07-29 05:45:00 【fK0pS】
HJ37 统计每个月兔子的总数 斐波那契数列
有一种兔子,从出生后第3个月起每个月都生一只兔子,小兔子长到第三个月后每个月又生一只兔子。
例子:假设一只兔子第3个月出生,那么它第5个月开始会每个月生一只兔子。
一月的时候有一只兔子,假如兔子都不死,问第n个月的兔子总数为多少?
数据范围:输入满足 1 \le n \le 31 \1≤n≤31
输入描述:
输入一个int型整数表示第n个月
输出描述:
输出对应的兔子总数
ip = input()
def df(n):
if n < 3: return 1
return df(n-1) + df(n-2)
print(df(ip))
这道题非常有意思:
每个月的兔子数量 = 上个月的兔子数量(因为兔子不会死,所以上个月的兔子,当前月还活着嘞) + 当前月新出生的兔子(当前月的先出生的兔子,就是前两个月的兔子数量,因为前两个月的兔子都是成年兔子,都具备生育能力) = df(n-1) +df(n-2)
典型的斐波那契数列
边栏推荐
- Database multi table query joint query add delete modify query
- Teacher Wang Shuyao's notes on operations research 09 linear programming and simplex method (Application of simplex table)
- 数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
- LDAP brief description and unified authentication description
- Teacher wangshuyao's notes on operations research 02 fundamentals of advanced mathematics
- Teacher Wu Enda's machine learning course notes 04 multiple linear regression
- Ali gave several SQL messages and asked how many tree search operations need to be performed?
- MySQL:当你CRUD时BufferPool中发生了什么?十张图就能说清楚
- Difference between CNAME record and a record
- NeuralCF-神经协同过滤网络
猜你喜欢

Federal learning backdoor attack summary (2019-2022)

C language memory stack and heap usage

Shallow reading of shared lock source code of abstractqueuedsynchronizer (AQS)

游戏资产的革命

【讲座笔记】如何在稀烂的数据中做深度学习?

10道面试常问JVM题

【论文阅读】TomoAlign: A novel approach to correcting sample motion and 3D CTF in CryoET

Ping principle

【冷冻电镜入门】加州理工公开课课程笔记 Part 3: Image Formation

CDM—码分复用(简单易懂)
随机推荐
API for using the new date class of instant
数据库系统概述
CDM—码分复用(简单易懂)
Analog volume leetcode [normal] 093. Restore IP address
说一下 TCP/IP 协议?以及每层的作用?
游戏资产的革命
DBAsql面试题
【冷冻电镜】Relion4.0——subtomogram教程
NeuralCF-神经协同过滤网络
模拟卷Leetcode【普通】081. 搜索旋转排序数组 II
Teacher Wu Enda's machine learning course notes 03 review of linear algebra
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
Teacher wangshuyao's notes on operations research 01 guidance and introduction
吴恩达老师机器学习课程笔记 02 单变量线性回归
【冷冻电镜】RELION4.0 pipeline命令总结(自用)
【讲座笔记】如何在稀烂的数据中做深度学习?
Teacher wangshuyao's notes on operations research 02 fundamentals of advanced mathematics
Enterprise manager cannot connect to the database instance in Oracle10g solution
基于噪声伪标签和对抗性学习的医学图像分割注释有效学习
【论文阅读】TomoAlign: A novel approach to correcting sample motion and 3D CTF in CryoET