LeetCode 82 Climbing Stairs
来源:互联网 发布:时时彩后二智能软件 编辑:程序博客网 时间:2024/06/08 17:04
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?
分析:
上台阶问题,属于最简单的动规问题。
子问题:上 i 级台阶有几种方式, dp[i],
状态转移方程:
因为有两种状态转移方式,我们就看这两种转移方式怎么组合转换,就这道题来讲,是相加的方式:
dp[i] = dp[i-1] + dp[i-2]
public class Solution { public int climbStairs(int n) { //最简单的动规问题了 if(n==0 || n==1 || n==2) return n; int[] dp = new int[n]; dp[0] = 1; dp[1] = 2; for(int i=2; i<n; i++) dp[i] = dp[i-1] + dp[i-2]; return dp[n-1]; }}
0 0
- LeetCode 82 Climbing Stairs
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- leetcode 107: Climbing Stairs
- [LeetCode] Climbing Stairs
- [LeetCode]Climbing Stairs
- [leetcode]Climbing Stairs
- LeetCode-Climbing Stairs
- [leetcode] Climbing Stairs
- LeetCode - Climbing Stairs
- LeetCode:Climbing Stairs
- Leetcode Climbing Stairs
- Divide Two Integers
- 开源模拟器汇总
- 去掉织梦DedeCMS列表推荐时被加粗的方法
- Window对象
- UVA - 10465 Homer Simpson
- LeetCode 82 Climbing Stairs
- 初次使用ssh架构搭建java ee的感想
- 第9周项目6百钱百鸡问题
- Document
- Posix共享内存区
- java杂技一:xml,json,Excel解析
- [leetcode] Path Sum
- DEDE Tag标签伪静态规矩在Apache中的实现办法
- 产品原型设计工具