procedure output(dep:integer); {杈撳嚭鍚勪釜欏剁偣鐨勭敾娉曢『搴弣 var sum,i,j:integer; begin inc(total); writeln(鈥檛otal:鈥?total); for i:=0 to dep do write(Path);writeln; end;
function ok(now,i:integer;var next:integer):boolean;{鍒ゆ柇絎琁鏉¤繛鎺ヨ竟鏄惁宸茶榪噠 var j,jj:integer; begin j:=0; jj:=0; while jj<>i do begin inc(j);if a[now,j]<>0 then inc(jj);end; next:=j; {鍒ゆ柇褰撳墠欏剁偣鐨勭I鏉¤繛鎺ヨ竟鐨勫彟涓绔槸鍝釜欏剁偣,鎵懼嚭鍚庤祴緇橬EXT浼犲洖} ok:=true; if (a[now,j]<>1) then ok:=false; {A[I,J]=0:鍘熸湰涓嶉殅 end; { =2:鏇捐蛋榪噠
procedure init; {鍒濆鍖杴 var i,j :integer; begin total:=0; {鏂規(guī)鎬繪暟} zongbianshu:=0; {鎬昏竟鏁皚 for i:=1 to max do for j:=1 to max do if a[i,j]<>0 then begin inc(bianshu);inc(zongbianshu);end; {姹備笌姣忎竴杈硅繛鎺ョ殑杈規(guī)暟bianshu} zongbianshu:=zongbianshu div 2; {鍥句腑鐨勬昏竟鏁皚 end;
procedure find(dep,nowpoint:integer); {dep:鐢葷鍑犳潯杈?nowpoint:鐜板湪鎵澶勭殑欏剁偣} var i,next,j:integer; begin for i:=1 to bianshu[nowpoint] do {涓庡綋鍓嶉《鐐規(guī)湁澶氬皯鏉$浉鎺?鍒欐湁澶氬皯縐嶈蛋娉晑 if ok(nowpoint,i,next) then begin {涓庡綋鍓嶉《鐐圭浉鎺ョ殑絎琁鏉¤竟鍙鍚?} {濡傛灉鍙,鍏舵眰鍑哄彟涓绔偣鏄疦EXT} a[nowpoint,next]:=2; a[next,nowpoint]:=2; {緗垚宸茶蛋榪囨爣蹇梷 path[dep]:=next; {璁板綍欏剁偣,鏂逛究杈撳嚭} if dep < zongbianshu then find(dep+1,next) {鏈悳绱㈠畬姣忎竴鏉¤竟} else output(dep); path[dep]:=0; {鍥炴函} a[nowpoint,next]:=1; a[next,nowpoint]:=1; end;
begin init; {鍒濆鍖?姹傝竟鏁扮瓑} for first:=1 to max do {鍒嗗埆浠庡悇涓《鐐瑰嚭鍙?灝濊瘯涓絎旂敾} fillchar(path,sizeof(path),0); path[0]:=first; {璁板綍鍏惰搗濮嬬殑欏剁偣} writeln(鈥檉rom point 鈥?first,鈥?鈥?;readln; find(1,first); {浠庤搗濮嬬偣first,涓鏉¤竟涓鏉¤竟鍦扮敾涓嬪幓} end.