我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
===============Python=============
# -*- coding:utf-8 -*- class Solution: def rectCover(self, number): # write code here if number == 0: return 0 dp1 = 1 dp2 = 2 for i in range(1, number): dp1, dp2 = dp2, dp1 + dp2 return dp1
===============Java==============
public class Solution { public int RectCover(int target) { if (target == 0) return 0; int dp1 = 1; int dp2 = 2; for (int i = 1; i < target; i++) { int tmp = dp1; dp1 = dp2; dp2 += tmp; } return dp1; } }