矩形覆盖
2016-10-25 20:10
204 查看
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
1.把最左边的2*1拿出来 剩下的有f(n-1) 左边的2*1有一种
2.把最左边的2*2拿出来 剩下的有f(n-2) 左边的2*2 有两种
f(n)=f(n-1)+f(n-2)
时间:33ms 占用内存:629k
1.把最左边的2*1拿出来 剩下的有f(n-1) 左边的2*1有一种
2.把最左边的2*2拿出来 剩下的有f(n-2) 左边的2*2 有两种
f(n)=f(n-1)+f(n-2)
时间:33ms 占用内存:629k
public class Solution { public int RectCover(int target) { int []count=new int[target+1]; if(target<=2) return target; count[0]=0; count[1]=1; count[2]=2; for(int i=3;i<=target;i++){ count[i]=count[i-1]+count[i-2]; } return count[target]; } }
相关文章推荐
- 矩形覆盖
- 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
- 剑指Offer--10.矩形覆盖
- 变态跳台阶 和 跳台阶 和 矩形覆盖
- UVA 10173 最小矩形覆盖(凸包+旋转卡壳)
- 分治法面试题(一):矩形覆盖
- 【NOIP2002提高组T4】矩形覆盖-DFS剪枝
- lintcode:直方图最大矩形覆盖
- 跳台阶\矩形覆盖\变态跳台阶
- 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
- 百度之星 矩形面积(最小矩形覆盖)
- 《剑指offer》矩形覆盖
- 【剑指offer】矩形覆盖
- [NOIP2002] 提高组 洛谷P1034 矩形覆盖
- 最小矩形覆盖(凸包旋转卡壳)
- 剑指offer——矩形覆盖
- 《剑指offer》-矩形覆盖
- 矩形覆盖
- HDU 1255 覆盖的面积 (矩形面积交)
- 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?