<p>You have two types of tiles: a <code>2 x 1</code> domino shape and a tromino shape. You may rotate these shapes.</p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/15/lc-domino.jpg" style="width: 362px; height: 195px;" />
<p>Given an integer n, return <em>the number of ways to tile an</em> <code>2 x n</code> <em>board</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/15/lc-domino1.jpg" style="width: 500px; height: 226px;" />
<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> 5
<strong>Explanation:</strong> The five different ways are show above.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
</ul>

class Solution {
public:
    int func(int n, bool a, bool b, map<vector<int>, int> &dp){
        int mod=1e9 + 7;
        if(n<2){
            if(!(a^b))return n;
            return 0;
        }
        if(dp.find({n, a, b})!=dp.end())return dp[{n, a, b}];
        if(a && b)return dp[{n, a, b}]=func(n-1, false, false, dp);
        else if(a && !b){
            return dp[{n, a, b}]=(func(n-1, false, true, dp)+func(n-1, true, true, dp))%mod;
        }else if(!a && b){
            return dp[{n, a, b}]=(func(n-1, true, false, dp)+func(n-1, true, true, dp))%mod;
        }else{
            return dp[{n, a, b}]=((func(n-1, false, false, dp)+func(n-1, true, true, dp))%mod+(func(n-1, true, false, dp)+func(n-1, false, true, dp))%mod)%mod;
        }
    }
    int numTilings(int n) {
        // map<vector<int>, int> dp;
        vector<vector<int>> prev(2, vector<int>(2, 0));
        int mod=1e9+7;
        prev[0][0]=1;
        prev[1][1]=1;
        for(int i=0; i<n-1; i++){
            vector<vector<int>> curr(2, vector<int>(2));
            for(int a=0; a<2; a++){
                for(int b=0; b<2; b++){
                    if(a && b){
                        curr[a][b]=prev[0][0];
                    }else if(!a && b){
                        curr[a][b]=(prev[1][0]+prev[1][1])%mod;
                    }else if(a && !b){
                        curr[a][b]=(prev[1][1]+prev[0][1])%mod;
                    }else{
                        curr[a][b]=((prev[0][0]+prev[0][1])%mod + (prev[1][0]+prev[1][1])%mod)%mod;
                    }
                }
            }
            prev=curr;
        }
        return prev[0][0];
    }
};
10200