41-Climbing Stairs-leetcode
- Climbing Stairs My Submissions QuestionEditorial Solution
Total Accepted: 106498 Total Submissions: 290003 Difficulty: Easy
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?
思路:so easy
重要的是思路清晰,对于n阶楼梯,可能由n-1阶迈上来的,也可能由n-2阶楼梯迈上来的,
就是一斐波纳挈数列,通项和为
这里的f(n)=an+1
这里程序有三种实现方式,递归效率最差,自底向上循环其次,最好的是常数级,用公式
class Solution {
public:
int climbStairs(int n) {
vector<int> vec(n+1,0);
vec[1]=1;vec[2]=2;
if(n<=2)return vec[n];
for(int i=3;i<=n;++i)
vec[i]=vec[i-1]+vec[i-2];
return vec[n];
}
};
41-Climbing Stairs-leetcode的更多相关文章
- Min Cost Climbing Stairs - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Min Cost Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题也是一道dp题.dp[i]表示爬到第i层 ...
- Climbing Stairs - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题是一题非常经典的DP题(拥有非常明显的重叠子结构).爬到n ...
- climbing stairs leetcode java
问题描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- [LeetCode] Climbing Stairs (Sequence DP)
Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...
- [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- [LeetCode] 70. Climbing Stairs 爬楼梯问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] 70. Climbing Stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
随机推荐
- OO_JAVA_电梯运行模拟_单元总结
电梯运行模拟--三次作业总结 目录 电梯运行模拟--三次作业总结 总体遵循的设计思路 逻辑解耦 电梯与调度器解耦 楼层信息的存储和变更与电梯.调度器解耦 调度器运行流程解耦 第一次电梯,蠢笨串行先到先 ...
- sql_exporter的使用
sql_exporter的使用 一.背景 二.sql-exporter的使用 1.下载 2.配置文件 1.sql_exporter.yml 2.collectors 目录中的配置文件 1.collec ...
- 热身训练1 Problem B. Harvest of Apples
http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意: 求 C(0,n)+C(1,n)+...+C(m,n) 分析: 这道题,我们令s(m,n) = C( ...
- A*,IDA*—高档次的暴搜
A*通过评价函数来判断当前状态是否可以到达最终状态(即可行性剪枝),来减少不必要的搜索. 例题--P2324 [SCOI2005]骑士精神 我们通过当前不在指定位置上的棋子个数为评价函数,\(used ...
- 全志TinaLinux编译错误fatal error: unicode/ucnv.h: No such file or directory
今天开始正式干活了 拿到一个全志Tina的板子还有一个SDK压缩包,要求我这周(只剩一天半...)就要把sdk编译通过并且把板子跑起来. 还特别跟我说他们试了下这个sdk编译没法通过,会报错... 竟 ...
- 我的笔记本电脑瞬间扩大一个T的容量!
前言 不知道有多少人在家里搭建中央存储设备的,也就是NAS.这个东西在我日常生活中,存储了大量的个人资料,家人们的照片,技术的资料,还有各种高清影视剧.搭配公网的IP,可以真正做到,任何时候任何地点的 ...
- Android Studio 查看SQLite数据库存储位置及文件
前言: 之前开发的一个记账本APP,用的是SQLite数据库,会有一些网友问如何查看数据库,这篇博文对此进行一个说明. 操作: 1.通过DDMS(Dalvik Debug Monitor Servic ...
- python编程中的流程控制
内容概要 成员运算 身份运算 流程控制 详细 1.成员运算 定义:判断某个个体在不在某个群体内 关键词:in(在) /// not in(不在) 例: num_list = [1, 2, 3, 4, ...
- Java Logback简易教程
本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可. 一.前言 本文以一个简单的项目为例,一步步展示logback的同步和异步配置方法,并且配置的日志要求满足阿里巴巴Java开发手册- ...
- IP基础 & 子网划分 & 路由寻址
IP地址详解 IP地址概念 就像用身份证号码来区别毎个人一样,为了区别 网上的每台计算机,我们给因特网上的每一台计算机一个唯一的编号 ,我们把它称为IP地址 IP地址就是一个唯一标识 ,是一段网络编码 ...