Sword Points Offer_Programming Questions_10

Topic description

We can use 2*1 small rectangles to cover larger rectangles horizontally or vertically. How many ways are there to cover a large 2*n rectangle with n small rectangles of 2*1 without overlapping?
class Solution {
public:
    int rectCover(int number) {
        vector<int>vt;
        vt.push_back(1);
        vt.push_back(2);
        for(int i=2; i<number; i++) {
            vt.push_back(vt[i-1]+vt[i-2]);
        }
        return vt[number-1];
    }
};

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324695021&siteId=291194637