矩形覆盖

  1. 题目描述
  2. 分析

题目描述

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

分析

斐波那契数列的应用


class Solution {
public:
    int rectCover(int number) {
        int res = 0;
        if (number == 0) res = 0;
        else if (number == 1) res = 1;
        else if(number == 2) res = 2;
        else {
            int f1 = 1,f2 = 2;
            for (int i = 3;i <= number;++i){
                res = f1 + f2;
                f1 = f2;
                f2 = res;
            }
        }
        
        return res;
    }
};

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 1056615746@qq.com

💰

Title:矩形覆盖

Count:127

Author:攀登

Created At:2019-12-26, 23:12:31

Updated At:2024-06-15, 15:53:35

Url:http://jiafeimao-gjf.github.io/2019/12/26/sword-%E7%9F%A9%E5%BD%A2%E8%A6%86%E7%9B%96/

Copyright: 'Attribution-non-commercial-shared in the same way 4.0' Reprint please keep the original link and author.

×

Help us with donation