当前位置:网站首页>climb stairs
climb stairs
2022-07-24 20:29:00 【To catty Hawthorn】
/*
climb stairs
Ideas ,stair(n) == stair(n-1) + stair(n-2)
That is to say n The scheme of stairs is equal to walking n-1 level add n-2 level
Recursive termination condition
if n == 1 return 1
if n== 2 return 2;
*/
#include<iostream>
using namespace std;
int stair(int n)
{
if(n == 1) return 1;
if(n == 2) return 2;
return stair(n - 1) + stair(n - 2);
}
int main()
{
int n;
while(cin >> n){
cout << stair(n) << endl;
}
return 0;
}
边栏推荐
- Make Huawei router into FTP server (realize upload and download function)
- Apache atlas version 2.2 installation
- Do you want to enroll in a training class or study by yourself?
- Wechat stores build order pages and automatically grab tickets
- Student achievement management system based on PHP
- Pychart tutorial: 5 very useful tips
- API data interface for historical data of A-share index
- Selenium uploads files in more ways than you think
- Preview and save pictures using uni app
- Appium obtains and clicks coordinates, which is very easy to use when elements are inconvenient to locate
猜你喜欢
![[training Day6] triangle [mathematics] [violence]](/img/57/d603886c202de7d46ea03487b633f5.png)
[training Day6] triangle [mathematics] [violence]

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用

Open source demo | release of open source example of arcall applet
![微服务架构 | 服务监控与隔离 - [Sentinel] TBC...](/img/28/8ca90e9dbd492688e50446f55959ff.png)
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...

Rhodamine B labeled PNA | rhodamine b-pna | biotin modified PNA | biotin modified PNA | specification information

Leetcode 146: LRU cache

Leetcode 1911. maximum subsequence alternating sum

Software testing interview tips | if you don't receive the offer, I'll wash my hair upside down

Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr

Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
随机推荐
Leetcode 300 longest increasing subsequence (greedy + binary search for the first element subscript smaller than nums[i]), leetcode 200 island number (deep search), leetcode 494 target sum (DFS backtr
The difference between delete, truncate and drop in MySQL
Hook 32-bit function using the method modified to JMP instruction
vlan技术
Cloud native observability tracking technology in the eyes of Baidu engineers
TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)
clip:learning transferable visual models from natural language supervision
When using vscode, the tab indentation changes from 4 spaces to small arrows (solved)
Markdown to PDF API data interface
Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket
Selenium uploads files in more ways than you think
Alibaba sentinel basic operation
Solve the problem of error l6218e undefined symbol XXX
Machine learning job interview summary: five key points that resume should pay attention to
Risk control system, implemented by flink+clickhouse!
Richview table table alignment
How does starknet change the L2 landscape?
VLAN Technology
[training Day9] light tank [dynamic planning]
Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)