当前位置:网站首页>题目 1004: 母牛的故事(递推)
题目 1004: 母牛的故事(递推)
2022-07-01 12:35:00 【51CTO】
文章目录
- Question
- Ideas
- Code
Question
Ideas
第n年的牛数 = 第n-1年的牛数 + 第n-3年前的数目(小牛四年后可以生)
Code
# 递推
list = [] #定义列表
list. append( 0) # 往list添加初始数据
list. append( 1) # 第一年奶牛数量为1
list. append( 2) # 第一年奶牛数量为2
list. append( 3) # 第一年奶牛数量为3
for i in range( 4, 1000): #预处理前1000年的奶牛数量
list. append( list[ i - 1] + list[ i - 3])
while True:
n = int( input()) #化为整型
if n == 0: #n ==0 时退出
break
print( list[ n]) #已经预处理了,所有直接输出就可以了
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
边栏推荐
- Using burpsuite to capture app packages
- 本科毕业四年:工作,辞职,结婚,买房
- "Analysis of 43 cases of MATLAB neural network": Chapter 40 research on prediction of dynamic neural network time series -- implementation of NARX based on MATLAB
- 项目部署,一点也不难!
- 【MAUI】为 Label、Image 等控件添加点击事件
- System test UI test summary and questions (interview)
- Mysql database knowledge collation
- Application of stack -- bracket matching problem
- Onenet Internet of things platform - create mqtts products and devices
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
猜你喜欢
Arm GIC (V) how arm TrustZone supports security interrupt analysis notes.
Double linked list related operations
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
Common chart usage of Bi tools
Onenet Internet of things platform - create mqtts products and devices
Onenet Internet of things platform - mqtt product equipment upload data points
How to install php7 and perform performance test using yum
第十四章 信号(四)- 多进程任务示例
双链表有关操作
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
随机推荐
Compile and debug net6 source code
BIM and safety in road maintenance-buildSmart Spain
顺序表有关操作
Fatal error: execution: there is no such file or directory
Need your own cognition
Teach you to complete the actual battle of image classification hand in hand -- Image Recognition Based on convolutional neural network
使用BurpSuite对app抓包教程
What are the PHP FPM configuration parameters
Ipv6-6to4 experiment
AI抠图工具
kubernetes之ingress探索实践
6.30 simulation summary
Good luck brought by years of persistence
[20211129] configuration du serveur distant du carnet de notes jupyter
数字信号处理——线性相位型(Ⅱ、Ⅳ型)FIR滤波器设计(2)
BIM and safety in road maintenance-buildSmart Spain
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
How to install php7 and perform performance test using yum
VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐