Domino and Tromino Tiling - Problem
You have two types of tiles:
- A 2 × 1 domino shape
- A tromino shape (L-shaped)
You may rotate these shapes. Given an integer n, return the number of ways to tile a 2 × n board. Since the answer may be very large, return it modulo 109 + 7.
In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.
Input & Output
Example 1 — Basic Case
$
Input:
n = 3
›
Output:
5
💡 Note:
There are 5 ways to tile a 2×3 board: (1) three vertical dominos, (2) one vertical + two horizontal, (3) two horizontal + one vertical, (4) two trominos, (5) different tromino arrangement
Example 2 — Minimum Case
$
Input:
n = 1
›
Output:
1
💡 Note:
Only one way to tile a 2×1 board: place one vertical domino
Example 3 — Small Even
$
Input:
n = 2
›
Output:
2
💡 Note:
Two ways to tile a 2×2 board: (1) two vertical dominos side by side, (2) two horizontal dominos stacked
Constraints
- 1 ≤ n ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Board dimensions: 2×n where n=3
2
Tiles
Two types: domino (1×2) and tromino (L-shaped)
3
Output
Count all possible ways to tile the board
Key Takeaway
🎯 Key Insight: Use DP with three states to track board coverage patterns efficiently
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code