当前位置:网站首页>1091: two or three things in childhood (multi instance test)
1091: two or three things in childhood (multi instance test)
2022-07-06 07:06:00 【Huaze flowers】
Title Description
Redraiment When I was a child, I liked to walk and jump , He likes to jump up and down the stairs best .
But when he was young, he could only go up one step at a time or jump up two steps at once .
Now there is N Steps , Please calculate Redraiment From 0 Step to N There are several ways to walk the steps .
Input
Input includes multiple sets of data .
Each set of data includes a row :N(1≤N≤40).
Enter to 0 end
Output
Each input includes an output .
by redraiment Arrive at n The number of different steps .
The sample input
1 3 0
Sample output
1 3
// Take one step , Jump two steps , from 0 Go to the N rank , Several walking methods
// Enter multiple groups N, With 0 end
// Output several ways
// Input :
//1
//3
//0
// Output :
//1
//3
#include <stdio.h>
int main()
{
int n,a[100],b,i;
a[0]=1;
a[1]=2;
while(scanf("%d",&n))
{
if(n==0)
break;
if(n==1)
printf("1\n");
else if(n==2)
printf("2\n");
else if(n>2)
{
for(i=2;i<=n;i++)
{
a[i]=a[i-1]+a[i-2];
}
printf("%d\n",a[n-1]);
}
}
return 0;
}
Running results :
Submit :
According to the title , You can find it by listing a few numbers , Fibonacci series can be used to calculate
Simply list a few examples of using Fibonacci sequence :
1. The bifurcation of trees
2. Number of petals
3. Rabbit breeding
4.1,2 Go up the steps
边栏推荐
- Bio model realizes multi person chat
- TS Basics
- Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
- leetcode841. 钥匙和房间(中等)
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
- 【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
- WPF之MVVM
- Windows Server 2016 standard installing Oracle
- Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
- BIO模型实现多人聊天
猜你喜欢
Raspberry pie serial port login and SSH login methods
19. Actual memory management of segment page combination
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
What is the difference between int (1) and int (10)? Senior developers can't tell!
ROS learning_ Basics
[advanced software testing step 1] basic knowledge of automated testing
树莓派串口登录与SSH登录方法
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
数据仓库建设思维导图
RichView TRVStyle 模板样式的设置与使用
随机推荐
Refer to how customer push e-commerce does content operation
Prefix and array series
Do you really know the use of idea?
Depth residual network
Bio model realizes multi person chat
Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
Three methods of adding color to latex text
Leetcode 78: subset
Arduino tutorial - Simon games
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
微信公众号无限回调授权系统源码 全网首发
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
leetcode59. 螺旋矩阵 II(中等)
CDN acceleration and cracking anti-theft chain function
Visitor tweets about how you can layout the metauniverse
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
树莓派串口登录与SSH登录方法
SEO学习的最好方式:搜索引擎
[hot100] 739. Température quotidienne