标签:bsp nbsp div over 矩形覆盖 斐波那契 offer ret style
题目:我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
思路:类似于斐波那契
class Solution { public: int rectCover(int number) { if (number == 0) return 0; int a = 1; int b = 1; int temp = 0; for (int i = 1; i < number; i++) { temp = b; b = a + b; a = temp; } return b; } };
标签:bsp nbsp div over 矩形覆盖 斐波那契 offer ret style
原文地址:https://www.cnblogs.com/lettleshel/p/10182713.html