Sword refers to offer: rectangle cover

test questions:

We can use a small rectangle of 2*1 to traverse or erect to cover a larger rectangle. How many methods are there to cover a 2*n large rectangle with n 2*1 small rectangles without overlapping?

码:

is also a summary of the law, and then use iteration, when n = 1, there is only one method; when n = 2, there are only two methods; when n = 3, only three Ways. Push back from n=3, assuming all the rectangles are filled, this is the case where n-1 is subtracted to get n-1; subtracting two rectangles is n-2; when subtracting 3 rectangles It will be found that no matter how it is filled from the n-3 case, the next step is the n-1 or n-2 case. That is to say, the case of n-3 has been included in n-1 or n-2.

class Solution {
public:
    int rectCover(int number) {
        if(number==0) return 0;
        int first = 1;
        int second = 2;
        while(number-->1){
            second = first + second;
            first = second - first;
        }
        return first;
    }
};