add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
24
solutions/7/q790/solution.go
Normal file
24
solutions/7/q790/solution.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package q790
|
||||
|
||||
const (
|
||||
TopHalf int8 = iota
|
||||
BottomHalf
|
||||
Full
|
||||
|
||||
Modulo int = 1e9 + 7
|
||||
)
|
||||
|
||||
func numTilings(n int) int {
|
||||
cache := make([][3]int, n+1)
|
||||
cache[0][Full] = 1
|
||||
cache[1][Full] = 1
|
||||
|
||||
for w := 2; w <= n; w++ {
|
||||
cache[w][Full] = (cache[w-1][Full] + cache[w-2][Full] + cache[w-1][TopHalf] + cache[w-1][BottomHalf]) % Modulo
|
||||
cache[w][TopHalf] = (cache[w-1][BottomHalf] + cache[w-2][Full]) % Modulo
|
||||
cache[w][BottomHalf] = (cache[w-1][TopHalf] + cache[w-2][Full]) % Modulo
|
||||
}
|
||||
return cache[n][Full]
|
||||
}
|
||||
|
||||
var _ = numTilings
|
||||
Loading…
Add table
Add a link
Reference in a new issue