AlgoFrames

Domino tilings

Standard · Write code · about 10 min

A board is 2 cells tall and n cells wide. A domino covers 2 cells and may stand upright or lie flat.

Return the number of ways to cover the whole board with dominoes. Look for a DP family you have seen before.

Example 1

Input:

[3]

Output:

3

Three upright; or one upright plus two flat, on the left or the right.

Example 2

Input:

[4]

Output:

5

Constraints

  • 0 ≤ n ≤ 45

Learn the idea first: Recognizing DP and choosing the state, a visual lesson.

More Recognizing DP and choosing the state problems