3283. Maximum Number of Moves to Kill All Pawns Hard

@problem@discussion
#Array#Math#Bit Manipulation#Breadth-First Search#Game Theory#Bitmask



1/**
2 * [3283] Maximum Number of Moves to Kill All Pawns
3 *
4 * There is a 50 x 50 chessboard with one knight and some pawns on it. You are given two integers kx and ky where (kx, ky) denotes the position of the knight, and a 2D array positions where positions[i] = [xi, yi] denotes the position of the pawns on the chessboard.
5 * Alice and Bob play a turn-based game, where Alice goes first. In each player's turn:
6 * 
7 * 	The player selects a pawn that still exists on the board and captures it with the knight in the fewest possible moves. Note that the player can select any pawn, it might not be one that can be captured in the least number of moves.
8 * 	<span>In the process of capturing the selected pawn, the knight may pass other pawns without capturing them</span>. Only the selected pawn can be captured in this turn.
9 * 
10 * Alice is trying to maximize the sum of the number of moves made by both players until there are no more pawns on the board, whereas Bob tries to minimize them.
11 * Return the maximum total number of moves made during the game that Alice can achieve, assuming both players play optimally.
12 * Note that in one move, a chess knight has eight possible positions it can move to, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.
13 * <img src="https://assets.leetcode.com/uploads/2024/08/01/chess_knight.jpg" style="width: 275px; height: 273px;" />
14 *  
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">kx = 1, ky = 1, positions = [[0,0]]</span>
18 * Output: <span class="example-io">4</span>
19 * Explanation:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/16/gif3.gif" style="width: 275px; height: 275px;" />
21 * The knight takes 4 moves to reach the pawn at (0, 0).
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">kx = 0, ky = 2, positions = [[1,1],[2,2],[3,3]]</span>
26 * Output: <span class="example-io">8</span>
27 * Explanation:
28 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/16/gif4.gif" style="width: 320px; height: 320px;" />
29 * 
30 * 	Alice picks the pawn at (2, 2) and captures it in two moves: (0, 2) -> (1, 4) -> (2, 2).
31 * 	Bob picks the pawn at (3, 3) and captures it in two moves: (2, 2) -> (4, 1) -> (3, 3).
32 * 	Alice picks the pawn at (1, 1) and captures it in four moves: (3, 3) -> (4, 1) -> (2, 2) -> (0, 3) -> (1, 1).
33 * </div>
34 * <strong class="example">Example 3:
35 * <div class="example-block">
36 * Input: <span class="example-io">kx = 0, ky = 0, positions = [[1,2],[2,4]]</span>
37 * Output: <span class="example-io">3</span>
38 * Explanation:
39 * 
40 * 	Alice picks the pawn at (2, 4) and captures it in two moves: (0, 0) -> (1, 2) -> (2, 4). Note that the pawn at (1, 2) is not captured.
41 * 	Bob picks the pawn at (1, 2) and captures it in one move: (2, 4) -> (1, 2).
42 * </div>
43 *  
44 * Constraints:
45 * 
46 * 	0 <= kx, ky <= 49
47 * 	1 <= positions.length <= 15
48 * 	positions[i].length == 2
49 * 	0 <= positions[i][0], positions[i][1] <= 49
50 * 	All positions[i] are unique.
51 * 	The input is generated such that positions[i] != [kx, ky] for all 0 <= i < positions.length.
52 * 
53 */
54pub struct Solution {}
55
56// problem: https://leetcode.com/problems/maximum-number-of-moves-to-kill-all-pawns/
57// discuss: https://leetcode.com/problems/maximum-number-of-moves-to-kill-all-pawns/discuss/?currentPage=1&orderBy=most_votes&query=
58
59// submission codes start here
60
61impl Solution {
62    pub fn max_moves(kx: i32, ky: i32, positions: Vec<Vec<i32>>) -> i32 {
63        0
64    }
65}
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn test_3283() {
75    }
76}
77


Back
© 2025 bowen.ge All Rights Reserved.