P1547 囧--逆转,然后再见--囧
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/20 06:17:38
P1547 囧--逆转,然后再见--囧
P1547 囧--逆转,然后再见--囧
P1547 囧--逆转,然后再见--囧
var
a:array[1..100,1..100]of longint;
f:array[0..10,0..10,0..10]of longint;
maxx,t,n,i,j,k,i1,i2:longint;
function min(a,b:longint):longint;
begin if a>b then exit(b) else exit(a);end;
function max(a,b,c:longint):longint;
begin if (a>b)and(a>c) then exit(a)
else if (b>a)and(b>c) then exit(b)
else exit(c);
end;
function minn(a,b,c:longint):longint;
begin if (a else if (b if (c end;
begin
readln(n);
for i:=1 to n-1 do
for j:=i+1 to n do
read(a[i,j]);
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
f[i,j,k]:=maxlongint;
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
f[i,j,k]:=maxlongint;
f[1,1,1]:=0;
maxx:=maxlongint;
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
if f[i,j,k]<>maxlongint then begin
t:=max(i,j,k)+1;
f[t,j,k]:=min(f[t,j,k],f[i,j,k]+a[i,t]);
f[i,t,k]:=min(f[i,t,k],f[i,j,k]+a[j,t]);
f[i,j,t]:=min(f[i,j,t],f[i,j,k]+a[k,t]);
if t=n then begin
if maxx>f[t,j,k] then maxx:=f[t,j,k];
if maxx>f[i,t,k] then maxx:=f[i,t,k];
if maxx>f[i,j,t] then maxx:=f[i,j,t];
end;
end;
writeln(maxx);
end.