forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0935.py
More file actions
28 lines (24 loc) · 713 Bytes
/
Copy path0935.py
File metadata and controls
28 lines (24 loc) · 713 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
from ctypes import c_uint32
class Solution:
hops = [(c_uint32 * 4)(4, 2, 2, 1)]
def knightDialer(self, N):
"""
:type N: int
:rtype: int
"""
if N == 1:
return 10
mod = 10**9 + 7
if N <= len(self.hops):
H = self.hops[N - 1]
else:
H = self.hops[-1]
for _ in range(len(self.hops), N):
H = (c_uint32 * 4)(2*(H[1] + H[2]), 2*H[3] + H[0], H[0], H[1])
for i in (0, 1, 2, 3):
H[i] %= mod
self.hops.append(H)
return sum(H) % mod
if __name__ == "__main__":
N = 2
print(Solution().knightDialer(N))