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

Sign up
Appearance settings

Commit 66537d2

Browse files
committed
Merge pull request #384 from 0xff-dev/790
Add solution and test-cases for problem 790
2 parents 9baa050 + 5881f46 commit 66537d2

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

‎leetcode/701-800/0790.Domino-and-Tromino-Tiling/README.md‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
# [790.Domino and Tromino Tiling][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes.
5+
6+
![shape](./lc-domino.jpg)
7+
8+
Given an integer n, return the number of ways to tile an `2 x n` board. Since the answer may be very large, return it **modulo** 10<sup>9</sup> + 7.
9+
10+
In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.
711

8-
**Example 1:**
12+
**Example 1:**
13+
14+
![example1](./lc-domino1.jpg)
915

1016
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
17+
Input: n = 3
18+
Output: 5
19+
Explanation: The five different ways are show above.
1320
```
1421

15-
## 题意
16-
> ...
1722

18-
## 题解
23+
**Example 2:**
1924

20-
### 思路1
21-
> ...
22-
Domino and Tromino Tiling
23-
```go
2425
```
25-
26+
Input: n = 1
27+
Output: 1
28+
```
2629

2730
## 结语
2831

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
const mod790 = 1000000007
4+
5+
func Solution(n int) int {
6+
if n == 1 {
7+
return 1
8+
}
9+
if n == 2 {
10+
return 2
11+
}
12+
dp := make([][]int, n+1)
13+
for i := 0; i < n+1; i++ {
14+
dp[i] = make([]int, 3)
15+
}
16+
dp[1][0], dp[1][1], dp[1][2] = 1, 0, 0
17+
dp[2][0], dp[2][1], dp[2][2] = 2, 1, 1
18+
19+
for i := 3; i <= n; i++ {
20+
dp[i][0] = (dp[i-1][0] + dp[i-2][0] + dp[i-1][1] + dp[i-1][2]) % mod790
21+
dp[i][1] = (dp[i-1][2] + dp[i-2][0]) % mod790
22+
dp[i][2] = (dp[i-1][1] + dp[i-2][0]) % mod790
23+
}
24+
return dp[n][0]
525
}

‎leetcode/701-800/0790.Domino-and-Tromino-Tiling/Solution_test.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 1, 1},
17+
{"TestCase2", 8, 258},
18+
{"TestCase3", 9, 569},
19+
{"TestCase4", 15, 65501},
1920
}
2021

2122
// 开始测试
@@ -30,10 +31,10 @@ func TestSolution(t *testing.T) {
3031
}
3132
}
3233

33-
//压力测试
34+
//压力测试
3435
func BenchmarkSolution(b *testing.B) {
3536
}
3637

37-
//使用案列
38+
//使用案列
3839
func ExampleSolution() {
3940
}
13.1 KB
Loading[フレーム]
46.8 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /