剑指Offer-Java-矩形覆盖

矩形覆盖


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

package com.hlq.test;

/**
 * @author helongqiang
 * @date 2020/5/12 21:44
 */

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

public class Solution {
    
    

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

猜你喜欢

转载自blog.csdn.net/helongqiang/article/details/106085962
今日推荐