#P2324. [SCOI2005] 骑士精神
[SCOI2005] 骑士精神
Description
On a board there are white knights and black knights, plus one empty cell. At any time, a knight may move into the empty cell following the knight's move (it can move to a cell where the x-coordinate differs by and the y-coordinate differs by , or the x-coordinate differs by and the y-coordinate differs by ).
Given an initial board, how can it be transformed, via moves, into the following target board:

To embody the "knight's spirit", they must finish in the minimal number of moves.
Input Format
The first line contains a positive integer (), indicating there are test cases.
Then follow matrices of size , where 0 denotes a white knight, 1 denotes a black knight, and * denotes the empty cell. There is no blank line between two test cases.
Output Format
For each test case, output one line. If the target state can be reached within moves (inclusive), output the minimal number of moves; otherwise, output -1.
2
10110
01*11
10111
01001
00000
01011
110*1
01110
01010
00100
7
-1
Hint

Translated by ChatGPT 5
京公网安备 11011102002149号