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. Windows Store App 应用程序安装目录

    前面介绍了如何对本地应用存储空间中的文件以及文件夹进行操作,在应用中除了可以对本地应用存储空间进行操作之外,还可以对应用程序安装目录进行相关操作.本节将通过一个示例,详细讲解如何对应用程序安装目录中的 ...

  2. GUID vs INT Debate【转】

    http://blogs.msdn.com/b/sqlserverfaq/archive/2010/05/27/guid-vs-int-debate.aspx I recently read a bl ...

  3. 利用LM神经网络和决策树去分类

    # -*- coding: utf-8 -*- import pandas as pd from scipy.interpolate import lagrange from matplotlib i ...

  4. 用PHP做服务器接口客户端用http协议POST访问安全性一般怎么做

    我的问题是,如果不做安全相关处理的话,一些可能改变数据库的操作可能会遭遇垃圾数据提交什么的,毕竟要找到这些信息只要找个http包就可以了 系统无用户登录 新手问题(从来没做过服务端开发),如果可以,给 ...

  5. 修改PE文件的入口函数OEP

    修改入口函数地址.这个是最省事的办法,在原PE文件中新增加一个节,计算新节的RVA,然后修改入口代码,使其指向新增加的节.当然,如果.text节空隙足够大的话,不用添加新节也可以. BOOL Chan ...

  6. hdu 4622 Reincarnation

    http://acm.hdu.edu.cn/showproblem.php?pid=4622 用字典树把每一个字符串对应成一个整数 相同的字符串对应到相同的整数上 把所用的串对应的整数放在一个数组里 ...

  7. 二模 (5)day1

    第一题: 题目大意:解一元一次方程(只有+-符号): 解题过程:直接处理处两边的x的系数和常数项,字符串的处理即可. 第二题: 题目大意:求逆序对数. 解题过程:直接归并排序. 第三题: 题目大意:多 ...

  8. debug实战:进程Hang+High CPU

    最近几周都在解决程序不稳定的问题,具体表现为程序(多进程)时不时的Hang住,同时伴随某个进程的High CPU.跟踪下来,基本都是各种死锁引起的.这里选取一个典型的场景进行分析. 1.抓dump分析 ...

  9. Java爬虫,信息抓取的实现

    转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/23272657 今天公司有个需求,需要做一些指定网站查询后的数据的抓取,于是花了点 ...

  10. 【C语言学习】-04 一维数组、字符数组

    一维数组.数组排序.字符数