forked from Adam-Jimenez/binarysearch-editorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDominos.py
More file actions
25 lines (20 loc) · 752 Bytes
/
Dominos.py
File metadata and controls
25 lines (20 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
Dominos
Similar to Tromino Theory;
We have two different states with different recurrence relations: The state where the board is flat and the state where there is a hole on the sides. We count the different states we can reach from each of them.
Explained in this video I made: https://www.youtube.com/watch?v=ccbPq-CqVRk
"""
from functools import lru_cache
MOD = (10**9) + 7
class Solution:
def solve(self, n):
@lru_cache(None)
def f(n):
if n == 0: return 1
if n < 0: return 0
return (f(n-2) + 2*f(n-2) + 2*g(n-2)) % MOD
@lru_cache(None)
def g(n):
if n <= 0: return 0
return (f(n-2) + g(n-2)) % MOD
return f(n)