矩形覆盖

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

resolution:

 public int RectCover(int target) {
        if(target == 1) return 1;
        if(target == 2) return 2;
        int result = 0;
        if(target > 2){
            result = RectCover(target - 1) + RectCover(target - 2);
        }
        return result;
    }

总结:该题主要是构建关系式f(n) = f(n-1) + f(n-2) ,构建的时候第一步是关键(横放第一块小矩形或者竖直放两块小矩形),这时学会和前一项f(n-1)和f(n-2)进行关联。首先将f(n) 设置为长为n时的种类数。

欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326840.html