[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 or 2 steps. In how many distinct ways can you climb to the top?
DP启蒙啊,做完这题终于对DP有个大概的认识了,自底向上检表,建完也就ok了,复杂度是O(n)
void iter(int acc, int n, vector<int> &table) {if (acc < 0) return;if (acc == n+1) return;int a = acc-1 < 0? 0 : acc-1;int b = acc-2 <0? 0 : acc-2;table.push_back(table[a] + table[b]);iter(acc+1, n, table); }int climbStairs(int n) {vector<int> table;table.push_back(0);table.push_back(1);table.push_back(2);if (n < 3) return table[n];iter(3, n,table);return table[n]; }
另附纯递归版,当然是TLE的
int climbstairs_TLE(int n) {if (n == 1) return 1;if (n == 2) return 2;return climbstairs_TLE(n-1) + climbstairs_TLE(n-2); }
TLE
转载于:https://www.cnblogs.com/agentgamer/p/4052988.html
[Leetcode] Climbing Stairs相关推荐
- LeetCode Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode | Climbing Stairs
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
- 【动态规划 斐波那切数列】LeetCode 746. Min Cost Climbing Stairs
LeetCode 746. Min Cost Climbing Stairs 本博客转载自:http://www.cnblogs.com/grandyang/p/8343874.html 存在无代价的 ...
- 【斐波那切数列】LeetCode 70. Climbing Stairs
LeetCode 70. Climbing Stairs 这是一道利用斐波那切数列求解的题目.求斐波那切数列有比较经典的4种方法 (1)递归法:复杂度太高 (2)迭代法:时间复杂度为O(n)O(n)O ...
- [勇者闯LeetCode] 70. Climbing Stairs
[勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...
- [LeetCode]70.Climbing Stairs
[题目] You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...
- 算法:Climbing Stairs(爬楼梯) 6种解法
说明 算法:Climbing Stairs(爬楼梯) LeetCode地址:https://leetcode.com/problems/climbing-stairs/ 题目: You are cli ...
- 10.2 动态规划算法套路及空间优化 —— Climbing Stairs Unique Paths
这一篇文章从最简单的动态规划题目开始,结合上一节动态规划三要素,以LeetCode两道基础的DP题目阐述DP问题的基本套路解法. 70. Climbing Stairs You are climbin ...
- 70. Climbing Stairs
70. Climbing Stairs 1. 题目 You are climbing a stair case. It takes n steps to reach to the top. Each ...
最新文章
- wp8.1 Study7: ListView 和GridView应用
- html5下拉列表默认值,element-ui中的select下拉列表设置默认值方法_简单_前端开发者...
- 链式前向星模板 建图+dfs+bfs+dijkstra
- Android中的Fragment使用
- 计算机二级和省考撞车了,事考、省考撞车?7月25日笔试,该怎么选?
- 使用ClickOnce部署VS2005中的WinForm应用程序.(ZT)
- 如何解决多线程并发访问一个资源的安全性问题?
- rtsp 报文转发_rtsp_proxy_server
- 怎样退出python的交互环境_python交互界面的退出方法
- Python加密保护-对可执行的exe进行保护
- 强连通图------(1)通过两次DFS或BFS判断是不是强连通图
- Scanner--控制台输入
- 设计模式(5)——单例模式的七种实现方式
- 课程设计 - 运动控制卡(云服务器)
- 水果店的售价应该怎么来定,水果店怎样确定价格
- 用lingo解决钢管下料问题
- java对文件分片处理
- 超视频时代,数据洪峰何解?
- 字模存储计算大学计算机是啥,大学计算机模拟题.doc
- 计算机辅助工装设计的应用研究,计算机辅助工装设计与管理.PPT
热门文章
- window下 php debug 的安装
- 35. 第一个只出现一次的字符(C++版本)
- 20. Prefer pass-by-reference-to-const to pass-by-value
- android mvvm点击事件,c# – MVVMCross:如何将Xamarin.Android事件绑定到ViewModel命令
- php简单富文本,JS简易版富文本编辑器实现代码
- modbus发送接收_自己编写MODBUS协议代码所踩过的坑
- mysql判断时间是否在某个区间_如何正确理解 RT 并监控 MySQL 的响应时间
- vrrp协议_Keepalived的高可用基石 - VRRP协议
- linux拆除模块驱动程序会跑吗,关于移植linux驱动问题,是不是还有别的办法?...
- emply() php,thinkphp3.2.3 分页代码分享