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

 

解析:不会,查看解析后:迭代法:

矩形2*1是什么样的:两行一列

矩形1*2是什么样的:一行两列

2*n是两行n列;

那么我们可以设定最后一列为2*1时:那么前边的摆放方法为f(n-1)

        我们可以设定最后两列为两个1*2时,那么前边的摆放方法为f(n-2)

加一起不就得了么

 

代码:

public class Solution {
    public int RectCover(int target) {
        if(target < 3){
            return target;
        }
        return RectCover(target - 1) + RectCover(target - 2);
    }
}

 

偷个图吧:

《剑指offer》JZ10矩形覆盖

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-07-29
  • 2022-02-15
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-01-03
  • 2021-04-04
  • 2021-07-05
  • 2021-06-08
  • 2021-07-17
相关资源
相似解决方案