Skip to content

Commit 9ff5f88

Browse files
authored
update: 添加问题“790.多米诺和托米诺平铺”的代码和题解(#918)
* clean: #915 Signed-off-by: LetMeFly666 <[email protected]> * archive: clean+todo Signed-off-by: LetMeFly666 <[email protected]> * notes: learn ai with shy Signed-off-by: LetMeFly666 <[email protected]> * refactor: rename https://github.com/LetMeFly666/LeetCode/pull/913\#discussion_r2072556534 Signed-off-by: LetMeFly666 <[email protected]> * words: en+jp Signed-off-by: LetMeFly666 <[email protected]> * feat: newSolution.py同时生成源码 close #916 Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“790.多米诺和托米诺平铺”的代码和题解(#918) 生成模板 close #916 close #912 Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 2365f66 commit 9ff5f88

19 files changed

+438
-323
lines changed

.changelog

Lines changed: 0 additions & 100 deletions
This file was deleted.

.commitmsg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
生成模板
2+
close #916
3+
close #912

AllProblems/_getResult.json

Lines changed: 0 additions & 181 deletions
This file was deleted.

AllProblems/_getResult.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

AllProblems/_gitResult.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

AllProblems/_moveResult.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-05 21:58:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-05 22:23:11
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
#ifdef FirstTry // Error
12+
const int MOD = 1e9 + 7;
13+
14+
class Solution {
15+
public:
16+
int numTilings(int n) {
17+
vector<int> dp(n + 1);
18+
dp[0] = 1;
19+
for (int i = 1; i <= n; i++) {
20+
dp[i] = (dp[i] + dp[i - 1]) % MOD;
21+
if (i >= 2) {
22+
dp[i] = (dp[i] + dp[i - 2]) % MOD;
23+
}
24+
if (i >= 3) {
25+
dp[i] = (dp[i] + dp[i - 3]) % MOD;
26+
dp[i] = (dp[i] + dp[i - 3]) % MOD;
27+
}
28+
}
29+
return dp.back();
30+
}
31+
};
32+
#else // FirstTry
33+
// SecondTry
34+
const int MOD = 1e9 + 7;
35+
36+
class Solution {
37+
public:
38+
int numTilings(int n) {
39+
if (n == 1) {
40+
return 1;
41+
}
42+
vector<int> dp(n + 1);
43+
dp[0] = dp[1] = 1;
44+
dp[2] = 2;
45+
for (int i = 3; i <= n; i++) {
46+
dp[i] = ((dp[i - 1] * 2) % MOD + dp[i - 3]) % MOD;
47+
}
48+
return dp.back();
49+
}
50+
};
51+
#endif // FirstTry
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-05 21:58:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-05 22:38:29
6+
*/
7+
package main
8+
9+
var MOD int = 1000000007
10+
11+
func numTilings(n int) int {
12+
if n == 1 {
13+
return 1
14+
}
15+
dp := make([]int, n + 1)
16+
dp[0] = 1
17+
dp[1] = 1
18+
dp[2] = 2
19+
for i := 3; i <= n; i++ {
20+
dp[i] = (dp[i - 1] * 2 % MOD + dp[i - 3]) % MOD
21+
}
22+
return dp[n]
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-05 21:58:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-05 22:28:23
6+
*/
7+
class Solution {
8+
private static int MOD = 1000000007;
9+
10+
public int numTilings(int n) {
11+
if (n == 1) {
12+
return 1;
13+
}
14+
int[] dp = new int[n + 1];
15+
dp[0] = dp[1] = 1;
16+
dp[2] = 2;
17+
for (int i = 3; i <= n; i++) {
18+
dp[i] = ((dp[i - 1] * 2) % MOD + dp[i - 3]) % MOD;
19+
}
20+
return dp[n];
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-05-05 21:58:06
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-05-05 22:25:56
6+
'''
7+
MOD = 1000000007
8+
9+
class Solution:
10+
def numTilings(self, n: int) -> int:
11+
if n == 1:
12+
return 1
13+
dp = [0] * (n + 1)
14+
dp[0] = dp[1] = 1
15+
dp[2] = 2
16+
for i in range(3, n + 1):
17+
dp[i] = (dp[i - 1] * 2 + dp[i - 3]) % MOD
18+
return dp[-1]

0 commit comments

Comments
 (0)