我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
解题思路:1.递归
public class Solution {
public int RectCover(int target) {
if(target==0)return 0;
if(target==1)return 1;
if(target==2)return 2;
return RectCover(target-1)+RectCover(target-2);
}
}
2.逐次计算
public class Solution {
public int RectCover(int target) {
if(target==0)return 0;
if(target==1)return 1;
if(target==2)return 2;
int One=1;
int Two=2;
int N=0;
for(int i=3;i<=target;i++){
N=One+Two;
One=Two;
Two=N;
}
return N;
}
}