MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TilingProblem

Function TilingProblem

dynamic/tilingproblem.go:10–22  ·  view source on GitHub ↗

TilingProblem returns the number of ways to tile a 2xN grid using 2x1 dominoes

(n int)

Source from the content-addressed store, hash-verified

8
9// TilingProblem returns the number of ways to tile a 2xN grid using 2x1 dominoes
10func TilingProblem(n int) int {
11 if n <= 1 {
12 return 1
13 }
14 dp := make([]int, n+1)
15 dp[0] = 1
16 dp[1] = 1
17
18 for i := 2; i <= n; i++ {
19 dp[i] = dp[i-1] + dp[i-2]
20 }
21 return dp[n]
22}

Callers 1

TestTilingProblemFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestTilingProblemFunction · 0.74