TilingProblem returns the number of ways to tile a 2xN grid using 2x1 dominoes
(n int)
| 8 | |
| 9 | // TilingProblem returns the number of ways to tile a 2xN grid using 2x1 dominoes |
| 10 | func 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 | } |
no outgoing calls