剑指Offer-10-矩形覆盖

题目描述

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

public class Solution {
    public int RectCover(int target) {
        int a = 1;
        int b = 2;
        int k = 0;
        if(target==1){
            return 1;
        }
        else if(target==2){
            return 2;
        }
        else{
            for(int i=3;i<=target;i++){
                k = b + a;
                a = b;
                b = k;
            }
        }
        return k;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_27378875/article/details/81128611