From ef9c473c21f386af2003f8fb5314ff62de4f0040 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 3 Aug 2024 21:41:39 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB790.=20Domino=20and=20Tromino?= =?UTF-8?q?=20Tiling=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/domino-and-tromino-tiling.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 go/domino-and-tromino-tiling.go diff --git a/go/domino-and-tromino-tiling.go b/go/domino-and-tromino-tiling.go new file mode 100644 index 0000000..ebb6e8a --- /dev/null +++ b/go/domino-and-tromino-tiling.go @@ -0,0 +1,14 @@ +package main + +const MOD int = 1_000_000_007 + +func numTilings(n int) int { + dp := [...]int{0, 1, 2, 5} + + for n >= 4 { + dp[0], dp[1], dp[2], dp[3] = dp[1], dp[2], dp[3], (2*dp[3]+dp[1])%MOD + n-- + } + + return dp[n] +}