题目链接

  题目要求

  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?

  做这道题容易陷入的思维就是:所有step加起来的总和是n。俺这种思维去解决这个问题的话会显得很复杂。

  按动态规划的思维,要爬到第n阶,可以从第n-1阶爬1阶到达,也可以从第n-2阶爬2阶到达,因此爬到第n阶的方法有这么多种:

dp[n] = dp[n - ] + dp[n - ]

  按此思维的程序代码如下:

 class Solution {
public:
int climbStairs(int n) {
if(n == || n == || n == )
return n; int * dp = new int[n + ];
dp[] = ;
dp[] = ;
dp[] = ; for(int i = ; i < n + ; i++)
dp[i] = dp[i - ] + dp[i - ]; return dp[n];
}
};

LeetCode之“动态规划”:Climbing Stairs的更多相关文章

  1. [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 ...

  2. Leetcode之70. Climbing Stairs Easy

    Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...

  3. 【LeetCode练习题】Climbing Stairs

    Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you c ...

  4. 【一天一道LeetCode】#70. Climbing Stairs

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 You are ...

  5. 【LeetCode】70. Climbing Stairs 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 题目大意 解题方法 递归 记忆化搜索 动态规划 空间压缩DP 日期 [L ...

  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】70 - 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(Java实现)

    这是悦乐书的第159次更新,第161篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第18题(顺位题号是70).你正在爬楼梯,它需要n步才能达到顶峰.每次你可以爬1或2步, ...

  9. LeetCode题解之Climbing Stairs

    1.题目描述 2.问题分析 使用动态规划. 3.代码 int climbStairs(int n) { ){ return n; } ]; dp[] = ; dp[] = ; dp[] = ; ; i ...

  10. LeetCode OJ:Climbing Stairs(攀爬台阶)

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

随机推荐

  1. EBS开发性能优化之查找需要优化的程序

    1.登陆数据库LINUX环境 使用 top 命令查看进程状况 [oratest@ebsdb~]$top top - 15:58:59 up 8 days, 22:04,  1 user,  load ...

  2. SpriteKit中节点的z-position

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交 ...

  3. FORM打开网页链接

     DECLARE l_server_url VARCHAR2(100); l_parameters VARCHAR2(200); BEGIN fnd_profile.get('APPS_WEB_A ...

  4. webStorm破解

    B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiw ...

  5. ormlite介绍一

    概述       ORMlite是类似hibernate的对象映射框架,主要面向java语言,同时,是时下最流行的android面向数据库的的编程工具. 官方网站:http://ormlite.com ...

  6. 6.3、Android Studio的CPU Monitor

    Android Monitor包含一个CPU Monitor,可以让你非常方便的监测你的应用的CPU的使用.它显示试试的CPU使用. 在CPU Monitor显示正在运行的应用 1. 打开一个项目 2 ...

  7. windows下实现win32俄罗斯方块练手,编程的几点心得

    编程珠玑2阅读笔记: 1.使用c语言性能监视器,完成对代码的调优工作 2.关联数组:  拓扑排序算法,可以用于当存在遮挡的时候决定三维场景的绘制顺序. 3.小型算法中的测试与调试工具 脚手架程序:&l ...

  8. ubuntu opengl 开发

    开发环境: eclipse,需要安装C++开发插件,在自带的源中查找安装C++开发工具包即可 下载安装gl库: sudo apt-get install libgl1-mesa-dev 下载安装glu ...

  9. Android的ScrollView和HorizontalScrollView-android学习之旅(四十一)

    HorizontalScrollView和ScrollView简介 ScrollView和HorizontalScrollView都继承于FrameLayout组件,两个都是容器,前者为里面的组件添加 ...

  10. Java --Annotation学习心得体会及笔记

    相对于注释这种给程序员看的信息: 注解,就是给程序看的解释性的语言,其作用就相当于配置文件的存在.其存在的意义在于以下几点: 优点: 方便的使程序员看到相关项的关联位置及关联方式等信息. 缺点: 由于 ...