当前位置:网站首页>题目 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.
边栏推荐
- Indefinite integral
- 腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
- Onenet Internet of things platform - mqtts product equipment connected to the platform
- Efforts at the turn of the decade
- 二叉树的链式存储
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6
- [20220605] Literature Translation -- visualization in virtual reality: a systematic review
- Huawei interview question: Recruitment
- 2022-06-28-06-29
- Onenet Internet of things platform - mqtt product equipment upload data points
猜你喜欢

Four years after graduation: work, resign, get married, buy a house

顺序表有关操作

项目部署,一点也不难!

Virtualenv+pipenv virtual environment management
![[106] 360 check font - check whether the copyright of local Fonts is commercially available](/img/a7/615e8000647b56f03a6a1d3dd81b6d.jpg)
[106] 360 check font - check whether the copyright of local Fonts is commercially available

Switch basic experiment
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4](/img/4f/bc6c39ef4f2d1c4bdad8420f7badac.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4

Onenet Internet of things platform - mqtts product equipment connected to the platform
![[20220605] Literature Translation -- visualization in virtual reality: a systematic review](/img/11/6c42957186bf530e8f9d4025a40197.png)
[20220605] Literature Translation -- visualization in virtual reality: a systematic review
![[speech signal processing] 3 speech signal visualization -- prosody](/img/06/5f57f9dfe3a0f2f70022706f7d4d17.jpg)
[speech signal processing] 3 speech signal visualization -- prosody
随机推荐
[20211129] jupyter notebook remote server configuration
MySQL的零拷贝技术
腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
[Maui] add click events for label, image and other controls
系统测试UI测试总结与问题(面试)
Onenet Internet of things platform - mqtts product equipment connected to the platform
Ansible的playbook
【MAUI】为 Label、Image 等控件添加点击事件
Leetcode (Sword finger offer) - 58 - ii Rotate string left
What are the PHP FPM configuration parameters
Eurake partition understanding
VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
基因检测,如何帮助患者对抗疾病?
[106] 360 check font - check whether the copyright of local Fonts is commercially available
AI matting tool
I wish you all a happy reunion
How to install php7 and perform performance test using yum
[20220605] Literature Translation -- visualization in virtual reality: a systematic review
Huawei interview question: Recruitment
队列的链式存储