Given n free plots arranged in a row, find the number of ways to assign buildings to these plots such that no two buildings are adjacent.
Each plot can either have a building placed on it or be left empty. Return the total number of valid arrangements.
Function Signature
def count_ways(n: int) -> int:
Rules
-
Two arrangements are different when some plot holds a building in one of them and is empty in the other.
-
Leaving every plot empty is a valid arrangement and counts once.
Constraints
Examples
Input: n = 3
Output: 5
The 5 valid arrangements are [E,E,E], [B,E,E], [E,B,E], [E,E,B] and [B,E,B], where B is a building and E is an empty plot.
Input: n = 4
Output: 8
The 8 valid arrangements are [E,E,E,E], [B,E,E,E], [E,B,E,E], [E,E,B,E], [E,E,E,B], [B,E,B,E], [B,E,E,B] and [E,B,E,B].
Input: n = 1
Output: 2
A single plot is either empty or holds a building, and it has no neighbor to conflict with.