Climbing Stairs
来源:互联网 发布:四川省网络试听作品 编辑:程序博客网 时间:2024/06/03 23:42
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
该题的难道是模型的建立:利用数学归纳法:
n=1, f(n)=1;
n=2,f(n)=2;
n=k(>=2), f(k)=f(k-2)+f(k-1);
#include<iostream>
using namespace std;
int climbStairs(int n)
{
if(n < 0)
return 0;
if(n <= 1)
return 1;
else
return climbStairs(n - 1) + climbStairs(n - 2);
}
int main()
{
int k,res;
cin >> k ;
res=climbStairs(k);
cout<< res <<endl;
return 1;
}
0 0
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Climbing Stairs
- Spring Boot Memory Performance
- Android 启动模式
- el表达式string强制转换成long报错
- android 5.0 新的特性
- 人才篇-如何识人用人
- Climbing Stairs
- mysql完成字符串分割
- 转载:C++ 实现银行排队服务模拟
- CodeForces 660A Co-prime Array
- 上传应用程序编译时报错:clang: error: unable to execute command: Segmentation fault: 11
- iOS 使用AFNetworking 3.1.0如何在请求头中加入cookie
- L3-001. 凑零钱-PAT团体程序设计天梯赛GPLT(01背包,动态规划)
- Quartz与Spring集成——启动调度器
- 以@为间隔,每5个字符为间距,分隔字符串