Press "Enter" to skip to content

Posts tagged as “tiling”

花花酱 LeetCode 790. Domino and Tromino Tiling


We have two types of tiles: a 2×1 domino shape, and an “L” tromino shape. These shapes may be rotated.

Given N, how many ways are there to tile a 2 x N board? Return your answer modulo 10^9 + 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.)


Idea: DP

dp[i][0]: ways to cover i cols, both rows of i-th col are covered
dp[i][1]:  ways to cover i cols, only top row of i-th col is covered
dp[i][2]:  ways to cover i cols, only bottom row of i-th col is covered

Solution 1: DP

Time complexity: O(N)

Space complexity: O(N)


C++ V2

Solution 2: DP

Another way to think about this problem

define: dp[i] ways to completely covert the i*2 board.