-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpferd.py
More file actions
33 lines (28 loc) · 688 Bytes
/
Copy pathpferd.py
File metadata and controls
33 lines (28 loc) · 688 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
26
27
28
29
30
31
32
33
from collections import defaultdict
from functools import cache
from typing import DefaultDict
M = 10**9 + 7
_steps = {
0: (6, 4),
1: (6, 8),
2: (7, 9),
3: (4, 8),
4: (3, 9, 0),
5: (),
6: (1, 7, 0),
7: (2, 6),
8: (1, 3),
9: (2, 4),
}
_dp = defaultdict(lambda: defaultdict(int))
def _build_dp(l: int):
global _dp
for i in _steps.keys():
_dp[1][i] = 1
for n in range(2, l + 1):
for i in _steps.keys():
_dp[n][i] = sum(_dp[n - 1][x] for x in _steps[n])
return sum(_dp[l][x] for x in _steps.keys() if (x != 8 and x != 0))
if __name__ == "__main__":
n = int(input().rstrip())
print(_build_dp(n))