此题无解,有诗为证:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
Move: array [1..4, 1..2] of Integer = ((-1, 0), (0, 1), (1, 0), (0, -1));
type
TMaze = array [1..5, 1..5] of Boolean;
TNode = record
Maze: TMaze;
x, y: Integer;
d: Integer
end;
var
Stack: array [1..24] of TNode;
Top: Integer;
i, j: Integer;
x, y: Integer;
procedure Print;
var
a: array [1..5, 1..5] of Integer;
i, j: Integer;
begin
FillChar(a, SizeOf(a), 0);
for i:=1 to Topdo
a[Stack.x, Stack.y]:=i;
for i:=1 to 5do
begin
for j:=1 to 5do
Write(a[i, j]:3);
WriteLn
end;
ReadLn;
Halt
end;
begin
for i:=1 to 5do
for j:=1 to 5do
if (i<>1) or (j<>4) then
begin
Top:=1;
FillChar(Stack[Top].Maze, SizeOf(TMaze), 0);
Stack[Top].Maze[1, 4]:=True;
Stack[Top].Maze[i, j]:=True;
Stack[Top].x:=i;
Stack[Top].y:=j;
Stack[Top].d:=0;
while Top>0do
begin
while Stack[Top].d<4do
begin
Inc(Stack[Top].d);
x:=Stack[Top].x+Move[Stack[Top].d, 1];
y:=Stack[Top].y+Move[Stack[Top].d, 2];
if (x in [1..5]) and (y in [1..5]) and (not Stack[Top].Maze[x, y]) then
begin
Inc(Top);
Stack[Top]:=Stack[Top-1];
Stack[Top].x:=x;
Stack[Top].y:=y;
Stack[Top].Maze[x, y]:=True;
Stack[Top].d:=0;
if Top=24 then
Print
end
end;
Dec(Top)
end
end;
WriteLn('Fault!');
ReadLn
end.