LeetCode_Climbing Stairs
ou are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb or steps. In how many distinct ways can you climb to the top?
分析:类似斐波那契序列,使用动态规划的思想。定义f(n)为台阶数为n时青蛙跳到台阶顶部的方法数。那么当n>2 时f(n) = f(n-1) + f(n-2) f(1) = 1; f(2) = 2;
class Solution {
public:
    int climbStairs(int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if(n <= ) return n;
        int f1 = , f2 = , res = ;
        for(int i = ; i <= n; ++i){
            res = f1 + f2;
            f1  = f2;
            f2  = res;
        }
        return res;
    }
};
LeetCode_Climbing Stairs的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
		You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ... 
- [LintCode] 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 ... 
- LintCode Climbing Stairs
		You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ... 
- 54. Search a 2D Matrix   &&   Climbing Stairs (Easy)
		Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ... 
- Climbing Stairs
		Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ... 
- 3月3日(6) Climbing Stairs
		原题 Climbing Stairs 求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了. class Solution { public: int climbStairs(int ... 
- Cllimbing Stairs [LeetCode 70]
		1- 问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe ... 
- leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法
		Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you ... 
随机推荐
- NuGet Package 管理工具
			http://npe.codeplex.com/downloads/get/clickOnce/NuGetPackageExplorer.application 
- fzu1759:数论高次幂降幂
			题目大意: 求 a^b mod c的值..但是b会非常大(10^1000000) 所以需要用到一个数论公式: A^x = A^(x % Phi(C) + Phi(C)) (mod C) 证明见ac大神 ... 
- DPDK2.1 linux上开发入门手册
			1引言 本文档主要包含INTEL DPDK安装和配置说明.目的是让用户快速的开发和运行程序.文档描述了如何在不深入细节的情况下在linux应用开发环境上编译和运行一个DPDK应用程序. 1.1文档总览 ... 
- 关于使用百度ueditor时的一些问题
			本来这些问题直接在百度贴吧里回答不就完事了,可是好死不死的,百度贴吧里老出现 未知错误,错误号:230274 看来还是算了,自己做一个随笔记录一下好了 关于我们获取里面的内容时,老是会有一个<p ... 
- uploadify不能正确显示中文的按钮文本的解决办法
			uploadify 目前不能正确显示中文的按钮文本. 我发现bug的原因是uploadify错误的使用了 js 的 escape 和 flash 的 unescape配对,而这2个是不兼容的.正确的转 ... 
- assertion的语法和语义
			.1) 语法表示 在语法上,为了支持assertion,Java增加了一个关键字assert.它包括两种表达式,分别如下: assert expression1; assert expression1 ... 
- hive优化要点总结
			个人认为总体两种思想: 1.让服务器尽可能的多做事情,榨干服务器资源,以最高系统吞吐量为目标 再好的硬件没有充分利用起来,都是白扯淡. 比如: (1) 启动一次job尽可能的多做事情,一个job能完 ... 
- hdu 3395
			KM裸题 每个鱼都认为自己是雄性,而且会攻击它认为是雌性的鱼,每个鱼只能被攻击一次,被攻击后会产卵(个数是给的两条鱼的值的异或运算) #include<string.h> #include ... 
- SUN-LDAP6.3_RHEL 5.0-卸载LDAP
			卸载LDAP 1.注销服务器 到目录/ldap/ldapinstance/dscc6/bin下 # ./dsccreg remove-server -h 主机名 /ldap/ldapinstance/ ... 
- Linux的VI/VIM
			参考自:http://www.cnblogs.com/itech/archive/2009/04/17/1438439.html 作者:iTech 出处:http://itech.cnblogs.co ... 
