当前位置:网站首页>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)
典型的斐波那契数列
边栏推荐
- IDEA找不到Database解决方法
- 模拟卷Leetcode【普通】093. 复原 IP 地址
- 实战!聊聊如何解决MySQL深分页问题
- Use of callable
- NeuralCF-神经协同过滤网络
- Teacher Cui Xueting's course notes on optimization theory and methods 00 are written in the front
- Phantom reference virtual reference code demonstration
- 【讲座笔记】如何在稀烂的数据中做深度学习?
- API for using the new date class of instant
- CNN convolutional neural network
猜你喜欢

联邦学习后门攻击总结(2019-2022)

SDN topology discovery principle

会话推荐中的价格偏好和兴趣偏好共同建模-论文泛读

Shallow reading of condition object source code

基于噪声伪标签和对抗性学习的医学图像分割注释有效学习

【冷冻电镜】Relion4.0——subtomogram教程

【冷冻电镜】RELION4.0之subtomogram对位功能源码分析(自用)

损失函数——交叉熵损失函数

Relationship between subnet number, host number and subnet mask

Software definition boundary SDP
随机推荐
Mutual conversion between Base64 and file
Security in quantum machine learning
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
Summary of 2022 SQL classic interview questions (with analysis)
Loss function -- cross entropy loss function
【干货备忘】50种Matplotlib科研论文绘图合集,含代码实现
5g service interface and reference point
Analog volume leetcode [normal] 093. Restore IP address
DM数据守护集群搭建
数据库持久化+JDBC数据库连接
Teacher Wu Enda's machine learning course notes 03 review of linear algebra
leetcode-592:分数加减运算
【经验】通过跳板机远程连接内网服务器的相关配置
Teacher wangshuyao wrote the notes of operations research course 00 in the front
2022年SQL经典面试题总结(带解析)
CVPR2022Oral专题系列(一):低光增强
吴恩达老师机器学习课程笔记 01 引言
MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear
Teacher wangshuyao's notes on operations research 06 linear programming and simplex method (geometric significance)
10 frequently asked JVM questions in interviews