<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 mod = 1e9+7;
    using ll = long long;
    ll solve(int n){
        int mod = 1e9+7;
        vector<ll> dp(n+1);
        if(n == 1 ||  n == 2){
            return n;
        }
        dp[0] = 1;
        dp[1] = 1;
        dp[2] = 2;

        for(int i = 3; i<=n; i++){
            dp[i] = (2*dp[i-1] + dp[i-3])%mod;
        }

        return dp[n];
    }
    ll dp[1001][1001];
    ll solve(int x, int y, int n){

        ll ans = 0;

        if(x == n && y == n) return 1;
        if(x > n || y > n) return 0;

        if(dp[x][y] != -1){
            return dp[x][y];
        }
        if(x != y){
            if(x < y){
                ans = ans + solve(x+2, y, n);
            }
            else{
                ans = ans + solve(x, y+2, n);
            }
        }
        else{
            ans = ans + solve(x+2, y+2, n);
        }

        if(x == y){
            ans = ans + solve(x+1, y+1, n);
            ans = ans + solve(x+1, y+2, n);
            ans = ans + solve(x+2, y+1, n);
        }

        if (y + 1 == x + 2) ans = ans + solve(x + 2, y + 1, n);
        if (x + 1 == y + 2) ans = ans + solve(x + 1, y + 2, n);
    
        return dp[x][y] = ans%mod;
    }
    int numTilings(int n) {
        
        
        memset(dp, -1, sizeof(dp));
        return solve(0, 0, n);
    }
};
16000