Imagine a charming residential street with n plots on each side (total of 2n plots). You're a city planner tasked with determining how many different ways houses can be placed while following a strict zoning rule: no two houses can be adjacent on the same side of the street.
Here's the interesting part: houses on opposite sides of the street can be directly across from each other - the adjacency rule only applies to houses on the same side.
Goal: Count the total number of valid house placement configurations.
Input: An integer n representing the number of plots on each side
Output: Number of ways to place houses modulo 109 + 7
Example: For n=2, you have 4 plots total (2 on each side). Some valid configurations include: no houses, houses only on opposite corners, houses on one side with a gap, etc.
Input & Output
Visualization
Time & Space Complexity
Single pass through n positions to build DP table
Only need to track previous state, can optimize to constant space
Constraints
- 1 โค n โค 1000
- Answer returned modulo 109 + 7
- No two houses can be adjacent on the same side of the street