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?

Subscribe to see which companies asked this question

简单的dp问题,代码如下:

 class Solution {
public:
int climbStairs(int n) {
if(n <= )
return n;
dp.resize(n + );
dp[] = ;
dp[] = ;
for(int i = ; i < n + ; ++i){
dp[i] += dp[i - ];
dp[i] += dp[i - ];
}
return dp[n];
}
private:
vector<int> dp;
};

java版本代码如下所示:

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

最新文章

  1. 解决VMware虚拟机宿主机与虚拟机通讯慢
  2. linux 网络编程比较好的文章
  3. Oracle 恢复被删除的数据,解决误操作删除数据
  4. CodeForces 688A-Opponents
  5. NEC学习 ---- 布局 -两列, 右侧定宽,左侧自适应
  6. The insertion sort algorithm expressed in pseudocode - 插入排序
  7. Concurrent Assertion
  8. Android 简单的代码混淆
  9. 【手打】LZW编码的C/C++实现
  10. MVC 树节点Table格式授权
  11. qt 坐标变换
  12. 用Ajax遍历三级下拉框
  13. PHPMYWIND4.6.6前台Refer头注入+后台另类getshell分析
  14. 【Python】【函数式编程】
  15. vue-cli 项目搭建
  16. JMeter出现“the target server failed to respond“的解决办法
  17. js命名空间写法
  18. VMWare------安装时出现无法将值写入注册表项
  19. configure: error: You need a C++ compiler for C++ support.
  20. docker tag 详解

热门文章

  1. 使用.NET Core和Vue搭建WebSocket聊天室
  2. SQL.Mysql中Cast()函数的用法
  3. php AES-128-CBC 加密 通信java
  4. 20145307《信息安全系统设计基础》第五周学习总结PT2
  5. 20145331实验四 &quot;Android开发基础&quot;
  6. uboot下如何查看内存里的数据
  7. 内核启动时在挂载ubi文件系统时提示UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch
  8. Can&#39;t connect to any repository: xxxxxx Error writing request body to server
  9. Java之JNDI详解
  10. 爬虫框架Scrapy之Spider