您的位置:首页 > 其它

矩形覆盖

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

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];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: