10.

我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。

请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?

是不是发现看不懂,哈哈;编程题就是这样,一定要归纳,手写过程;

n = 1,则 1;

n = 2.则1,1横1,1竖;是不是有点眼熟;

n= 3,则1,1,1横,1,1横1竖,1竖1,1,横;。。。还要再说么?

注意不能省2,因为0为0;

public class Solution {
public int RectCover(int target) {
  if(target == 0 || target == 1 || target == 2) {
    return target;
  }

  return RectCover(target-1)+RectCover(target-2);
  }
}

猜你喜欢

转载自www.cnblogs.com/wzQingtTian/p/10661807.html
10.