矩形覆盖

题目描述

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

class Solution {
public:
    int rectCover(int number) {
        if(number<=2) return number;
        int cover1 = 2;
        int cover2 = 1;
        int coverN = 0;
        for(int i = 3;i<=number;i++){
            coverN = cover1+cover2;
            cover2 = cover1;
            cover1 = coverN;
        }
        return coverN;
    }
};

 

你可能感兴趣的:(剑指)