1. 程式人生 > >【劍指offer第十題】矩形覆蓋

【劍指offer第十題】矩形覆蓋

題目描述

我們可以用2*1的小矩形橫著或者豎著去覆蓋更大的矩形。請問用n個2*1的小矩形無重疊地覆蓋一個2*n的大矩形,總共有多少種方法?

n=0,0種;

n=1,1種;

n=2,2種;

n=3,3種;

n=4,5種;

n=5,8種;

又是斐波那契數列 。

public class Solution {
    public int RectCover(int target) {
        int first=1;
        int second=2;
        int result=0;
        if(target<3){
           return target;
        }
        for(int i=3;i<=target;i++){
            result=first+second;
            first=second;
            second=result;
        }
        return result;
    }
}