luogu#P2324. [SCOI2005] 骑士精神

    ID: 1323 Type: RemoteJudge 1000ms 128MiB Tried: 1 Accepted: 1 Difficulty: 7 Uploaded By: Tags>搜索2005四川各省省选广度优先搜索 BFS启发式搜索启发式迭代加深搜索 IDA*A* 算法折半搜索 meet in the middle

[SCOI2005] 骑士精神

Problem Description

On a 5×55 \times 5 board there are 1212 white knights and 1212 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 11 and the y-coordinate differs by 22, or the x-coordinate differs by 22 and the y-coordinate differs by 11).

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 TT (T10T \le 10), indicating there are TT test cases.

Then follow TT matrices of size 5×55 \times 5, 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 1515 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