解题思路
采用动态规划思路。参考题解。
核心代码如下:
const long long mod = 1e9 + 7;
class Solution {
public:
int numTilings(int n) {
vector<vector<long long>> dp(n + 1, vector<long long>(4));
dp[0][3] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][3];
dp[i][1] = (dp[i - 1][0] + dp[i - 1][2]) % mod;
dp[i][2] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
dp[i][3] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3]) % mod;
}
return dp[n][3];
}
};
标签:tromino,790,int,多米诺,托米,tiling
From: https://www.cnblogs.com/hql5/p/16884551.html