⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 salesman.pas

📁 PASCAL光盘资料PASCAL光盘资料PASCAL光盘资料
💻 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 + -