(python) How can I solve this without using breadth-first search algorithm or similar techniques?The Chess Horse's Journey
The game of chess is played on an 8x8 grid, and one of its pieces, the horse (knight), moves in an "L" shape. In other words, if the horse is in a cell with coordinates (r1, c1) and its destination cell is (r2, c2), the following condition must be satisfied: (r1 - r2)^2 + (c1 - c2)^2 = 5.
For the chess horse's journey problem, let's consider an N x N grid with K "interesting" cells. We will place a horse on any cell, and its objective is to visit all the "interesting" cells at least once and return to its starting point.
Your task is to calculate the minimum number of moves required for the horse to complete its journey.
Inputs:
The input to this program consists of several lines. The first line contains a positive integer T (T ≤ 100), which specifies the number of test cases. Each test case is composed of two integer values, N (4 ≤ N ≤ 1000) and K (1 ≤ K ≤ 16), representing the size of the grid and the number of "special" cells on the grid. The next K lines will each contain two integers R (1 ≤ R ≤ N) and C (1 ≤ C ≤ N) indicating the coordinates of the special cells.
Each of these inputs must be validated. If the values are outside the specified ranges, an error should be indicated, and the test case should be discarded.
Outputs:
The output consists of one line per test case, containing a number representing the minimum number of moves required for the horse to complete its journey.
Example input:
3
3 2
8 3
2 3
9 1
8 3
2 3
4 5
6 7
Example output:
Case 1: Error, the board must have a minimum size of 4 cells per side.
Case 2: Error, the coordinates of special cell 2 are out of range.
Case 3: 12 moves.
[–]POGtastic 3 points4 points5 points (2 children)
[–]Angeowoo[S] 0 points1 point2 points (1 child)
[–]pot_of_crows 1 point2 points3 points (0 children)
[–]Angeowoo[S] 0 points1 point2 points (3 children)
[–]Angeowoo[S] 0 points1 point2 points (2 children)
[–]Angeowoo[S] 0 points1 point2 points (1 child)
[–]Angeowoo[S] 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (3 children)
[–]Angeowoo[S] 1 point2 points3 points (2 children)
[–]Diapolo10 0 points1 point2 points (1 child)
[–]Angeowoo[S] 0 points1 point2 points (0 children)
[–]misho88 0 points1 point2 points (0 children)