You have two types of tiles: a 2 x 1
domino shape and a tromino shape. You may rotate these shapes.
![lc-domino.jpg][1]
Given an integer n, return the number of ways to tile an 2 x n
board. Since the answer may be very large, return it modulo
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.
dp
考虑这么一种平铺的方式:在第 iii 列前面的正方形都被瓷砖覆盖,在第 iii 列后面的正方形都没有被瓷砖覆盖(iii 从 111 开始计数)。那么第 iii 列的正方形有四种被覆盖的情况: ![1.png][2] 一个正方形都没有被覆盖,记为状态 0;
只有上方的正方形被覆盖,记为状态 1;
只有下方的正方形被覆盖,记为状态 2;
上下两个正方形都被覆盖,记为状态 3。
使用 dp[i][s]\textit{dp}[i][s]dp[i][s] 表示平铺到第 iii 列时,各个状态 sss 对应的平铺方法数量。考虑第 i−1i-1i−1 列和第 iii 列正方形,它们之间的状态转移如下图(红色条表示新铺的瓷砖):
状态转移方程:
初始时
```c++
class Solution {
const long long mod=1e9+7;
public:
int numTilings(int n) {
vector<vector
[1]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[2]: http://www.fengdaxian.xyz/usr/uploads/2022/11/370693592.png
[3]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[4]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[5]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[6]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[7]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[8]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg
[9]: http://www.fengdaxian.xyz/usr/uploads/2022/11/3406384932.jpg