《剑指offer》矩形覆盖
来源:互联网 发布:老炮儿网络剧 编辑:程序博客网 时间:2024/05/31 19:33
【 声明:版权所有,转载请标明出处,请勿用于商业用途。 联系信箱:libin493073668@sina.com】
题目链接:http://www.nowcoder.com/practice/72a5a919508a4251859fb2cfb987a0e6?rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
题目描述
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
思路
一个小矩形只有两种铺法,要么横着要么竖着,因此这道题的原理跟跳台阶是完全一样的
class Solution{public:int rectCover(int n){if(n==0) return 1;int a = 1;int b = 2;if(n<=2)return n;int ans;for(int i = 3; i<=n; i++){ans = a+b;a = b;b = ans;}return ans;}};
0 0
- 剑指offer--矩形覆盖
- 剑指offer--矩形覆盖
- 《剑指offer》矩形覆盖
- 剑指offer 矩形覆盖
- 《剑指offer》矩形覆盖
- 剑指 offer:矩形覆盖
- 【剑指Offer】矩形覆盖
- 剑指offer 矩形覆盖
- 剑指offer-矩形覆盖
- 剑指Offer 矩形覆盖
- 剑指offer 矩形覆盖
- [剑指offer]矩形覆盖
- 《剑指offer》-矩形覆盖
- 【剑指offer】覆盖矩形
- 《剑指offer》矩形覆盖
- 剑指offer - 矩形覆盖
- 【剑指offer】矩形覆盖
- 剑指offer-矩形覆盖
- 游戏常用英文单词缩写
- [leetcode]Word Frequency
- 【bzoj1179】【apio2009】Atm【强连通分量缩点+spfa】
- 安装MPlayer for linux(FC7)详细介绍--适合菜鸟
- Java 内部类
- 《剑指offer》矩形覆盖
- GitHub--Windows下command line创建与提交
- Java之美[从菜鸟到高手演变]之智力题【史上最全】
- Spark on Yarn+Hbase环境搭建指南(四)NTP服务设置
- shell 自动执行参数脚本并判断(一个折腾的下午)
- jQuery常用的元素查找方法总
- PS混合模式
- 数组与ARRAYLIST的关系与区别
- px、dp和sp,这些单位有什么区别?