矩形覆盖

题目描述:我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?

实现语言:Java

public class Solution {
    public int RectCover(int n) {
        if(n<=2){
            return n;
        }
        return RectCover(n-1)+RectCover(n-2);
    }
}

实现语言:Java

public class Solution {
    public int RectCover(int n) {
        if(n<=1){
            return n;
        }
        int tmp=0,pre=1,res=1;
        for(int i=2;i<=n;++i){
            tmp=res;
            res=pre+tmp;
            pre=tmp;
        }
        return res;
    }
}

 

posted on 2018-12-28 13:52  lina2014  阅读(114)  评论(0编辑  收藏  举报

导航