forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1240.go
39 lines (37 loc) · 768 Bytes
/
1240.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var mem [][]int
func tilingRectangle(n int, m int) int {
mem = make([][]int, n + 1)
for i := 0; i <= n; i++ {
mem[i] = make([]int, m + 1)
for j := 0; j <= m; j++ {
mem[i][j] = 10000
}
}
return dfs(n, m)
}
func dfs(x, y int) int {
if mem[x][y] != 10000{
return mem[x][y]
}
if (x == 11 && y == 13) || (x == 13 && y == 11) {
return 6
}
if x == y {
return 1
}
res := x * y
for i := 1; i <= x/2; i++ {
res = min(res, dfs(i, y) + dfs(x - i, y))
}
for j := 1; j <= y/2; j++ {
res = min(res, dfs(x, j) + dfs(x, y - j))
}
mem[x][y] = res
return res
}
func min(a, b int) int {
if a < b {
return a
}
return b
}