Skip to content

Commit fe2d61a

Browse files
authored
Create 790. Domino and Tromino Tiling (#787)
2 parents d6ceb35 + 661e814 commit fe2d61a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

790. Domino and Tromino Tiling

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
const int MOD = 1e9 + 7;
4+
int numTilings(int n) {
5+
if (n == 0) return 1;
6+
if (n == 1) return 1;
7+
if (n == 2) return 2;
8+
9+
vector<long long> dp(n+1), prefix(n+1);
10+
dp[0] = 1;
11+
dp[1] = 1;
12+
dp[2] = 2;
13+
prefix[0] = 1;
14+
prefix[1] = 2;
15+
prefix[2] = 4;
16+
17+
for (int i = 3; i <= n; ++i) {
18+
dp[i] = (dp[i-1] + dp[i-2] + 2 * prefix[i-3]) % MOD;
19+
prefix[i] = (prefix[i-1] + dp[i]) % MOD;
20+
}
21+
22+
return dp[n];
23+
}
24+
};

0 commit comments

Comments
 (0)