101 Logo
onenoughtone

Problem Statement

Domino and Tromino Tiling

You have two types of tiles: a 2 × 1 domino shape and a tromino shape. You may rotate these shapes.

Domino and Tromino Shapes

Given an integer n, return the number of ways to tile an 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.

Examples

Example 1:

Input: n = 3
Output: 5
Explanation: The five different ways are shown below. [Image showing 5 different tilings of a 2x3 board]

Example 2:

Input: n = 1
Output: 1
Explanation: There is only one way to tile a 2x1 board.

Constraints

  • 1 <= n <= 1000

Problem Breakdown

To solve this problem, we need to:

  1. This problem can be solved using dynamic programming.
  2. We need to define multiple states to represent different configurations of the board.
  3. The recurrence relation involves considering all possible ways to place dominos and trominos.
  4. The modulo operation needs to be applied at each step to avoid integer overflow.
ProblemSolutionCode
101 Logo
onenoughtone