935. Knight Dialer Medium

@problem@discussion
#Dynamic Programming



1/**
2 * [935] Knight Dialer
3 *
4 * The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:
5 * A chess knight can move as indicated in the chess diagram below:
6 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/18/chess.jpg" style="width: 402px; height: 402px;" />
7 * We have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell (i.e. blue cell).
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/18/phone.jpg" style="width: 242px; height: 322px;" />
9 * Given an integer n, return how many distinct phone numbers of length n we can dial.
10 * You are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.
11 * As the answer may be very large, return the answer modulo 10^9 + 7.
12 *  
13 * Example 1:
14 * 
15 * Input: n = 1
16 * Output: 10
17 * Explanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.
18 * 
19 * Example 2:
20 * 
21 * Input: n = 2
22 * Output: 20
23 * Explanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]
24 * 
25 * Example 3:
26 * 
27 * Input: n = 3131
28 * Output: 136006598
29 * Explanation: Please take care of the mod.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= n <= 5000
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/knight-dialer/
40// discuss: https://leetcode.com/problems/knight-dialer/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn knight_dialer(n: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_935() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.