题目描述
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
比如n=3时,2*3的矩形块有3种覆盖方法:
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
解题思路:对于这种规律型的题目,可以先手动算一下当n=1,2,3,4时,有多少种方法,从而找出规律。本题和青蛙跳台阶一样,依然是f(n)=f(n-1)+f(n-2)
public class Solution {
public int rectCover(int target) {
if(target<3) return target;
else return rectCover(target-1)+rectCover(target-2);
}
}