我们可以用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];
}
}