?? salesman.pas
字號:
program salesman;
var a:array[1..40,1..40] of byte;
n,i,j:byte;
min ,m :longint;
bj:array[1..40] of boolean;
input,output:text;
procedure init;
begin
assign(input,'salesman.in');
reset(input);
readln(input,n);
for i:=1 to n do for j:=1 to n do read(input,a[i,j]);
close(input);
fillchar(bj,sizeof(bj),true);
min:=99999999;
m:=0;
end;
procedure road(step,line:byte);
var i,j,k:byte;
begin
if step=n then
if m+a[line,1]<min then min:=m+a[line,1] else
else
for i:=2 to n do
if (i<>line) and bj[i] then
begin
m:=m+a[line,i];
bj[line]:=false;
if m <min then road(step+1,i);
m:=m-a[line,i]; bj[line]:=true;
end;
end;
procedure print;
begin
assign(output,'salesman.out');
rewrite(output);
writeln(output,min);
close(output);
end;
begin
init;
road(1,1);
print
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -