当前位置:网站首页>Hj37 statistics of the total number of rabbits per month Fibonacci series
Hj37 statistics of the total number of rabbits per month Fibonacci series
2022-07-29 07:00:00 【fK0pS】
HJ37 Count the total number of rabbits every month Fibonacci sequence
There is a kind of rabbit , From the day after birth 3 A rabbit has been born every month since last month , The little rabbit grows to the third month and gives birth to another rabbit every month .
Example : Suppose a rabbit 3 Months was born , So it's the first 5 A rabbit will be born every month from the beginning of next month .
There was a rabbit in January , If the rabbits don't die , Ask No n What's the total number of rabbits in a month ?
Data range : Input satisfaction 1 \le n \le 31 \1≤n≤31
Input description :
Enter a int An integer of type denotes the th n Months
Output description :
Output the corresponding total number of Rabbits
ip = input()
def df(n):
if n < 3: return 1
return df(n-1) + df(n-2)
print(df(ip))
This question is very interesting :
The number of rabbits per month = The number of rabbits last month ( Because rabbits don't die , So last month's rabbit , The current month is still alive ) + The new born rabbit in the current month ( The first born rabbit of the current month , The number of rabbits in the first two months , Because the rabbits in the first two months are adult rabbits , All have fertility ) = df(n-1) +df(n-2)
A typical Fibonacci sequence
边栏推荐
- 模拟卷Leetcode【普通】172. 阶乘后的零
- 数仓建模,什么是宽表?如何设计?好处与不足
- How to write controller layer code gracefully?
- Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
- Ali gave several SQL messages and asked how many tree search operations need to be performed?
- Shallow reading of shared lock source code of abstractqueuedsynchronizer (AQS)
- SDN topology discovery principle
- Teacher wangshuyao's notes on operations research 05 linear programming and simplex method (concept, modeling, standard type)
- IDEA找不到Database解决方法
- 矩阵分解与梯度下降
猜你喜欢

MySQL:当你CRUD时BufferPool中发生了什么?十张图就能说清楚

Basic knowledge of MySQL (high frequency interview questions)

IDEA中实现Mapper接口到映射文件xml的跳转

vim文本编辑器的一些使用小技巧

IDEA找不到Database解决方法

C language memory stack and heap usage

2D cartoon rendering - advanced skills

Etcd principle

【冷冻电镜|论文阅读】子断层平均 M 软件解读:Multi-particle cryo-EM refinement with M

分享一些你代码更好的小建议,流畅编码提搞效率
随机推荐
Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
Mutual conversion between Base64 and file
王树尧老师运筹学课程笔记 10 线性规划与单纯形法(关于检测数与退化的讨论)
数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
【经验】通过跳板机远程连接内网服务器的相关配置
【论文阅读 | cryoET】Gum-Net:快速准确的3D Subtomo图像对齐和平均的无监督几何匹配
leetcode-592:分数加减运算
线程同步—— 生产者与消费者、龟兔赛跑、双线程打印
JMM memory model concept
SDN topology discovery principle
Teacher wangshuyao's notes on operations research 04 fundamentals of linear algebra
王树尧老师运筹学课程笔记 02 高等数学基础
mysql查询区分大小写
吴恩达老师机器学习课程笔记 01 引言
Simulation volume leetcode [ordinary] 172. Zero after factorial
模拟卷Leetcode【普通】150. 逆波兰表达式求值
Relative date used by filter in salesforce
Teacher wangshuyao's notes on operations research course 08 linear programming and simplex method (simplex method)
王树尧老师运筹学课程笔记 05 线性规划与单纯形法(概念、建模、标准型)
Why does 5g N2 interface control plane use SCTP protocol?