这题我是用搜索的方法来做的
搜的时候,如果当前的费用大于tj,那么就不用再搜了,小于tj就把当前的费用放进tj里,最后输出tj
var n,i,j,tj:longint; a:array[0..1000,0..1000]of longint; f:array[0..1000]of boolean; procedure search(dep,m:longint); var i:longint; begin if dep>n then if m<tj then begin tj:=m; exit; end; if m>=tj then exit; for i:=1 to n do if f[i]=false then begin f[i]:=true; search(dep+1,m+a[i,dep]); f[i]:=false; end; end; begin readln(n); for i:=1 to n do begin for j:=1 to n do read(a[i,j]); readln; end; fillchar(f,sizeof(f),false); tj:=100000; search(1,0); write(tj); end.