/*
* @lc app=leetcode id=790 lang=cpp
*
* [790] Domino and Tromino Tiling
*/
// @lc code=start
class Solution {
public:
int numTilings(int n) {
const int mod = 1000000007;
vector<vector<long long>> dp(3, vector<long long>(3, 0));
dp[0][0] = 1;
int first = 0, second = 0, third = 0;
for(int i=0;i<n;i++){
first = (first+1) % 3;
second = (first+2) % 3;
third = (first+1) % 3;
dp[0][first] = (dp[0][second] + dp[1][second] + dp[2][second] + dp[0][third]) % mod;
dp[1][first] = (dp[0][third] + dp[2][second]) % mod;
dp[2][first] = (dp[0][third] + dp[1][second]) % mod;
}
return dp[0][first];
}
};
// @lc code=end
No.293 - LeetCode[790] Domino and Tromino Tiling - 经典dp
最新推荐文章于 2024-11-08 23:27:36 发布