819. Tiling Problem — Count Ways to Tile 2×N Floor (Modulo 10^9+7)

HardRecursionRecursion

Count the number of ways to tile a 2×N floor using 1×2 dominoes, mod 10^9+7. This equals the (N+1)-th Fibonacci number. f(0)=1, f(1)=1, f(n)=f(n-1)+f(n-2).

Input: A non-negative integer n.

Output: Integer mod 10^9+7.

Examples

Example 1
Input: 3
Output: 3
Explanation: 3 tilings of 2×3.
Example 2
Input: 4
Output: 5
Explanation: 5 tilings of 2×4.
Example 3
Input: 0
Output: 1
Explanation: Empty floor: 1 way.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →