zoukankan      html  css  js  c++  java
  • 剑指offer10-矩形覆盖

    题目描述

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

     

    比如n=3时,2*3的矩形块有3种覆盖方法:

    思路:
    代码:
    class Solution {
    public:
        int rectCover(int number) {
            //和斐波那契数列问题一样
            if(number==0) return 0;
            if(number==1) return 1;
            if(number==2) return 2;
            int count_first = 1;
            int count_second = 2;
            int count;
            if(number>=3)
            {
                for(int i=2;i<number;i++)
                {
                    count = count_first + count_second;
                    count_first = count_second;
                    count_second = count;
                }
            }
            return count;
    
        }
    };
  • 相关阅读:
    【模板】并查集
    排队布局
    list
    js获取宽度
    js获取按键
    sublime 自定义快捷代码
    file
    git add Untracked files
    git branch
    git
  • 原文地址:https://www.cnblogs.com/loyolh/p/12870827.html
Copyright © 2011-2022 走看看