题目描述
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
本质还是斐波那契数列,只是f(0)=1(不太明白);别的和跳台阶那题一样
代码如下:
public class Solution {
public int RectCover(int target) {
int[] result = {1,1,2};
if(target<=2){
return result[target];
}
int fone = 1;
int ftwo = 2;
int fN = 0;
for(int i=2;i<target;i++){
fN = fone+ftwo;
fone = ftwo;
ftwo = fN;
}
return fN;
}
}