Knight Dialer
Last updated
Last updated
A chess knight can move as indicated in the chess diagram below:
.
This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makesN-1
hops. Each hop must be from one key to another numbered key.
Each time it lands on a key (including the initial placement of the knight), it presses the number of that key, pressingN
digits total.
How many distinct numbers can you dial in this manner?
Since the answer may be large,output the answer modulo10^9 + 7
.
Example 1:
Example 2:
Example 3:
Note:
1
<
= N
<
= 5000
分析
python过不了,java
8个方向dfs,记得map里要包含step,map[xtep][x][y]