Problem · Dynamic Programming
Domino and Tromino Tiling
Learn this problemProblem statement
You have a board with 2 rows and n columns. Cover every square exactly once using any number of the following tiles:
- A
2 x 1domino, which may be rotated. - An L-shaped tromino made of three unit squares, which may be rotated.
Return the number of distinct complete tilings modulo 10^9 + 7. Two tilings are different when at least one tile covers a different set of squares.
Function
numTilings(n: int) → intExamples
Example 1
n = 1return = 1One vertical domino is the only complete tiling.
Example 2
n = 3return = 5There are three domino-only tilings and two tilings that use a complementary pair of trominoes.
Example 3
n = 5return = 24The dynamic recurrence counts 24 complete tilings.
Constraints
1 <= n <= 1000.