【題解】LeetCode 790. Domino and Tromino Tiling

【題目敘述】https://leetcode.com/problems/domino-and-tromino-tiling/

class Solution {
public:
    int numTilings(int n) {
        long long a[1005][2] = {}, p = 1e9+7;
        a[0][0] = 1;
        a[0][1] = 0;
        a[1][0] = 1;
        a[1][1] = 0;
        for (int i = 2; i <= n; i++){
            a[i][0] = (a[i-1][0]+a[i-1][1]+a[i-2][0])%p;
            a[i][1] = (a[i-2][0]*2+a[i-1][1])%p;
            //cout << a[i][0] << " " << a[i][1] << "\n";
        }
        return a[n][0];
    }
};
分享本文 Share with friends