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?

思路:

最简单的DP问题:递归+查表

代码:

 int climbStairs(int n) {
vector<int> memo(n+, -);//忘了在memo[0]没有意义的时候,数组初始大小加一。。。
return climb(n, memo);
} int climb(int n, vector<int>& memo){//忘了加&,就会Time Limit Exceeded
if(n < ){
return -;
}
else if(n <= ){
memo[n] = n;
return n;
} if (memo[n-] == -)
memo[n-] = climb(n-, memo);//修改了递归函数名之后没有更改其他函数体中的引用
if(memo[n-] == -)
memo[n-] = climb(n-, memo);
//return memo[n-1] + 2*memo[n-2];//等等,子问题中好像有重叠
return memo[n-] + memo[n-];
}

【题解】【DP】【Leetcode】Climbing Stairs的更多相关文章

  1. [LeetCode] Climbing Stairs (Sequence DP)

    Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...

  2. [LeetCode] Climbing Stairs 爬梯子问题

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  3. Leetcode: climbing stairs

    July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...

  4. [leetcode DP]70. Climbing Stairs

    一共有n个台阶,每次跳一个或者两个,有多少种走法,典型的Fibonacii问题 class Solution(object): def climbStairs(self, n): if n<0: ...

  5. LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)

    题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...

  6. LeetCode——Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  7. [Leetcode] climbing stairs 爬楼梯

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  8. [LeetCode] Climbing Stairs 斐波那契数列

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  9. leetcode Climbing Stairs python

    class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int " ...

  10. Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs)

    Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs) 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost ...

随机推荐

  1. 经验分享:使用 Restyle.js 简化 CSS 预处理

    Andrea Giammarchi的restyle.js是一个新的,基于JavaScript的CSS预处理器,能够运行在服务端(通过Node.js)或者浏览器中.它宣称自己是“一种简化的CSS方法”, ...

  2. B’QConf(北京软件质量大会)记

    下午从公司加班回来,顺路到淘宝(大望路)参加B'QConf(北京软件质量大会).淘宝所在的国家广告产业园原来是一个菜市场,已经有大约6年没有到那一带活动了.之所以记得这么清楚,是因为6年前曾经从那里的 ...

  3. PHP 多线程扩展(正儿八经的线程)pthreads安装

    环境CentOS 6.3 64bit,php 5.4.5 pthreads需要线程安全环境, 下载php的安装包,解压: tar zxvf php-5.4.5.tar.gz//名字是不是这个我不确定, ...

  4. Zabbix源码包安装

    Zabbix源码包安装 Cenos5.3 Basic server 安装顺序 Libxml2 Libmcrypt Zlib Libpng Jpeg:需要创建目录jpeg  /bin  /lib   / ...

  5. linux安装svn服务端不使用apache

    一.安装 1.查看是否安装cvs rpm -qa | grep subversion 2.安装 yum install subversion 3.测试是否安装成功 /usr/bin/svnserve ...

  6. ECMAScript 6新特性(1)数组篇

    数组现有的方法: .concat():连接两个或更多的数组,并返回结果. .join():把数组的所有元素放入一个字符串.元素通过指定的分隔符进行分隔. .pop():删除并返回数组的最后一个元素 . ...

  7. wp8.1 Study9:针对不同的屏幕和手机方向调整UI

    一.预备知识 现在不同屏幕大小WP8.1手机越来越多,那么在设计UI时,这需要我们考虑这个问题.在WP中,比例因子(a scale factor)能很好的解决问题,而且在微软系统的PC/平板/手机都是 ...

  8. 最好的Java IDE之争:Eclipse PK IntelliJ IDEA

    话说,好马配好鞍,一个好的工匠,必定要有一套好的工具才能打造出最好的工艺给大家.之前,Plumbr团队里的所有成员都使用Eclipse编辑器,而如今,大家都成为IntelliJ IDEA用户.那么,到 ...

  9. SVN服务器配置实战

    [需求] 为公司多个部门建立的SVN仓库compay 公司部门和人员构成 A部门 (zhangsan,lisi,wanger,mazi) B部门(jia,yi,bing,ding) C部门(chun, ...

  10. java基础-002

    1.Java虚拟机和“平台无关语言” Java虚拟机是可以执行字节码的虚拟机进程.Java源文件被编译成被Java虚拟机执行的字节码文件. Java被设计成允许应用程序运行在任意的平台,而不需要程序员 ...