leetcode_70题——Climbing Stairs(简单DP题)
2015-06-05 09:28
453 查看
Climbing Stairs
Total Accepted: 54579 Total Submissions: 158996My SubmissionsQuestion Solution
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
Have you met this question in a real interview?
Yes
No
Discuss
#include<iostream> #include<vector> using namespace std; int climbStairs(int n) { if(n==0||n==1) return 1; int *ptr=new int[n+1]; for(int i=0;i<n+1;i++) ptr[i]=0; ptr =1; ptr[n-1]=1; for(int i=n-2;i>=0;i--) ptr[i]=ptr[i+1]+ptr[i+2]; int last=ptr[0]; delete []ptr; return last; } int main() { cout<<climbStairs(3)<<endl; }
相关文章推荐
- 11. Container With Most Water
- Naive Bayes在mapreduce上的实现
- leetcode 217: Contains Duplicate
- 正确使用Block避免Cycle Retain和Crash
- LeetCode "Contains Duplicate III"
- sgu252:Railway Communication(费用流)
- Climbing Stairs
- 从main函数中argc和argv开始学习
- [LOJ 1038] Race to 1 Again
- How did your survive waiting
- TurboMail智能防御企业邮箱盗号和退信攻击
- tools:context=".MainActivity的作用
- 用libaio读写文件时遇到的问题
- UVA514 Rails
- UVA442 Matrix Chain Multiplication
- light oj 1038 - Race to 1 Again(概率dp求期望 记忆化搜索)
- rails4.2~devise邮箱测试
- hdu 5009 Paint Pearls
- HDU 2476 - String painter(区间DP)
- 【leetcode】Contains Duplicate II