当前位置:网站首页>Zzuli:1055 rabbit reproduction
Zzuli:1055 rabbit reproduction
2022-07-03 14:34:00 【Snake_____】
Title Description
This is an interesting classical mathematical problem , Famous Italian mathematician Fibonacci A question was raised : There's a couple of rabbits , From the day after birth 3 A couple of rabbits are born every month from . The little rabbit grows to the third place 3 Two months later, a couple of rabbits were born every month . According to this rule , Suppose no rabbits died , In the first month, there was a couple of newborn rabbits , Ask No n How many pairs of rabbits in a month ?
Input
Enter the number of months n(1<=n<=44).
Output
Output No n How many pairs of rabbits in a month .
The sample input Copy
3
Sample output Copy
2
Tips
This topic is a classic introduction to recursion : use f(n) It means the first one n Number of rabbits in months , be : f(n) = f(n-1) + Number of rabbits born this month and , Number of rabbits born this month = f(n-2) ( Because every rabbit that existed last month , A new rabbit will be born this month ) therefore ,f(n) = f(n-1) + f(n-2) That's the famous one fabinacci The sequence , The latter is equal to the sum of the first two : 1 1 2 3 5 8.....
#include <stdio.h>
int main()
{
int i,n,a=1,b=1,c;
scanf("%d",&n);
if(n==1)
{
printf("%d",a);
}
else
{
for(i=2;i<n;i++)
{
c=a;
a=a+b;
b=c;
}
printf("%d",a);
}
return 0;
}边栏推荐
猜你喜欢

MySQL multi table query subquery

必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿

Puzzle (016.3) is inextricably linked

一文了解微分段应用场景与实现机制

分布式事务(Seata) 四大模式详解

NPM install is stuck with various strange errors of node NPY

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

Eight sorts

Pyqt interface production (login + jump page)

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
随机推荐
String substitution
556. 下一个更大元素 III : 简单构造模拟题
Add ZABBIX calculation type itemcalculated items
7-23 currency conversion (using array conversion)
7-19 check denomination (solve binary linear equation)
Convert string to decimal integer
Ultra simple mobile map development
Zabbix添加Calculated items后保存页面成空白
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
7-6 mixed type data format input
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Understand the application scenario and implementation mechanism of differential segment
洛谷P4047 [JSOI2010]部落划分 题解
String reverse order
7-3 rental (20 points)
Jiuyi cloud black free encryption free version source code
puzzle(016.4)多米诺效应
Address book sorting
动态获取权限
7-22 tortoise and rabbit race (result oriented)