1. 程式人生 > >劍指 Offer - 10:矩陣覆蓋

劍指 Offer - 10:矩陣覆蓋

題目描述

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

題目連結:https://www.nowcoder.com/practice/72a5a919508a4251859fb2cfb987a0e6

解題思路

同第8題跳臺階相同

public class Solution {
    public int RectCover(int target) {
        if (target <= 2) return target;
        int[
] result = new int[target+1]; result[1] = 1; result[2] = 2; for (int i = 3; i <= target; i++) { result[i] = result[i-1] + result[i-2]; } return result[target]; } }