Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe2d61a

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

File tree

Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed

‎790. Domino and Tromino Tiling

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.