9.1 A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.

LeetCode上的原题,请参见我之前的博客Climbing Stairs 爬梯子问题

class Solution {
public:
int countWays(int n) {
vector<int> res(n + , );
for (int i = ; i <= n; ++i) {
res[i] = res[i - ] + res[i - ];
}
return res.back();
}
};

[CareerCup] 9.1 Climbing Staircase 爬楼梯的更多相关文章

  1. climbing stairs(爬楼梯)(动态规划)

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

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

  3. Climbing Stairs爬楼梯——动态规划

    题目描写叙述: 初阶:有n层的台阶,一開始你站在第0层,每次能够爬两层或者一层. 请问爬到第n层有多少种不同的方法? 进阶:假设每次能够爬两层.和倒退一层,同一个位置不能反复走,请问爬到第n层有多少种 ...

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

  5. LeetCode 70. Climbing Stairs爬楼梯 (C++)

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

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

  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]70. 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 爬楼梯

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

随机推荐

  1. 使用Ant构建struts2 web工程,自动编译,打包成war

    c&c++语言通常使用make脚本来构建和管理自己的工程,同样java也有自己的构建工具(Ant),使用时需要写一个biuld.xml,有点类似c&c++里的makefile. 一.首 ...

  2. 大写金额字符串生成 C#实现

    思路: 中文对金额的描述以四位为一组, 只考虑一万亿以内的数字则每组内以千.百.十和[亿\万\元]区分各位 连续的零按一个处理,组内最低位的零可略去 无角无分说整,有角无分只说角,无角有分说零X分,有 ...

  3. Java中读取properties资源文件

    一.通过ResourceBundle来读取.properties文件 /** * 通过java.util.resourceBundle来解析properties文件. * @param String ...

  4. mysql插入数据与删除重复记录的几个例子(收藏)

    mysql插入数据与删除重复记录的几个例子 12-26shell脚本实现mysql数据的批量插入 12-26mysql循环语句插入数据的例子 12-26mysql批量插入数据(insert into ...

  5. android中progress进度条的使用

    activity.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  6. 05_最长公共子序列问题(LCS)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P60 问题7: 问题描述:给两个子序列A和B,求长度最大的公共子序列.比如1,5,2,6,8,和2,3,5,6,9,8,4的最长公共子序 ...

  7. nyoj 120 校园网络

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=120 思路:先将原图强连通缩点为新图,统计新图中入度,出度为0的点的个数,两者取最大值即为 ...

  8. CSS中的 backgroundPosition 属性

    body { background-image:url('bgimage.gif'); background-repeat:no-repeat; background-attachment:fixed ...

  9. Sql Practice 2

    之前写了一个SP用来向dimention table插入0 -1 dummy row的值,但今天在process adventureworksdw2008示例 数据库的时候报错,查看了一下,是因为自己 ...

  10. java coder的水平

    写java写了也12年了,不决的自己是高手,但是也体会了一些变化.总的来说,Java可以分成几个层次: 首先是需求理解层次,这个层次的coder能理解需求,把需求转化成代码: 第二个层次是单测,能够对 ...