[Leetcode]-Climbing Stairs
2015-07-06 10:57
288 查看
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?
Hide Tags: Dynamic Programming
题目:爬楼梯,需要爬到第N步,每次你可以爬层2步或者1步,问总共有几种方法?
思路:Dynamic Programming(动态规划)
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Hide Tags: Dynamic Programming
题目:爬楼梯,需要爬到第N步,每次你可以爬层2步或者1步,问总共有几种方法?
思路:Dynamic Programming(动态规划)
//DP(Dynamic Programming) algorithms 见算法导论 //S = S[n-1] + S[n-2] ; //S[1] = 1 ; //S[2] = 2 ; int climbStairs(int n) { if( n == 0) return 0; if( n == 1) return 1; if( n == 2) return 2; int one_step = 1; int two_step = 2; int sum_ways = 0; int i = 0 ; for(i=2;i<n;i++) { sum_ways = one_step + two_step; one_step = two_step; two_step = sum_ways; } return sum_ways; }
相关文章推荐
- 帝国CMS留言板回复后发送EMAIL通知客户
- explain 和 desc 详解
- AEAI CRM_v1.5.0_20150703发版说明
- 人工智能思想进入我国的历史回顾
- RAID5阵列中两块磁盘告警后的处理步骤
- windows 2003建立RAID-0 RAID0-1 RAID-5 卷。(vmware环境)
- 帝国CMS留言板回复后发送EMAIL通知客户
- 卓越的TurboGate邮件网关企业邮箱的安全保障
- HDU4630:No Pain No Game(线段树)
- OMSA在Windows服务器上安装部署(服务器监控,RAID在线操作)
- LeetCode Factorial Trailing Zeroes (阶乘后缀零)
- LeetCode 219: Contains Duplicate II
- Lightoj 1090 - Trailing Zeroes (II)
- LeetCode 217: Contains Duplicate
- Contains Duplicate III
- Clairewd’s message
- leetcode:Contains Duplicate和Contains Duplicate II
- DELL R710在阵列卡上做raid的图例
- RAID损坏后 对数据的完整备份
- leetCode 11.Container With Most Water (数轴上容器) 解题思路和方法