10、矩形覆盖_java

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

比如n=3时,2*3的矩形块有3种覆盖方法:

public class Solution {
        public int RectCover(int target) {
            if(target<0)
                return -1;
            if(target<=1)
                return target;
            int a = 1;
            int b = 1;
            int result= 0;
            for(int i=1;i<target;i++){
                result=a+b;
                a=b;
                b=result;
            }
            return result;
        }
    }
发布了80 篇原创文章 · 获赞 0 · 访问量 2690

猜你喜欢

转载自blog.csdn.net/qq_41017546/article/details/104679176