主题:低手与狗皆可进入
Hx
[专家分:0] 发布于 2005-06-21 20:20:00
中国象棋的马从半张棋盘的左下角跳到右上角,如果规定只许往右跳,
请用程序找出所有的解。
(请赐教,高手们!!!!);
回复列表 (共2个回复)
沙发
zhaoren [专家分:420] 发布于 2005-07-23 19:54:00
骂人者,无人应也~~~
板凳
sd5774188 [专家分:260] 发布于 2005-07-25 21:27:00
还是把我的程序贴下吧!
递归:program yb(input,output);
const walkx:array[1..4]of integer=(-2,-1,1,2);
walky:array[1..4]of integer=(1,2,2,1);
var way:array[1..5,1..9]of integer;
s:integer;
procedure search(x,y:integer);
procedure print;
var i,j:integer;
begin
way[1,9]:=1;
for i:=1 to 5 do begin
for j:=1 to 9 do
if way[i,j]=1 then
write('*',' ')
else
write('.',' ');
writeln;
end;
writeln;
inc(s);
end;
var i,x1,y1:integer;
begin
if (x=1)and(y=9) then print else
for i:=1 to 4 do
begin
x1:=x+walkx[i];
y1:=y+walky[i];
if (x1<=5)and(x1>=1)and(y1>=1)and(y1<=9)and(way[x1,y1]=0)then
begin
way[x1,y1]:=1;
search(x1,y1);
way[x1,y1]:=0;
end;
end;
end;
begin
s:=0;
fillchar(way,sizeof(way),0);
way[5,1]:=1;
search(5,1);
writeln('Total=',s);
end.
想要非递归的吗?那你答应你以后不再骂人……
我来回复