有一个点过不了
var n,i,j,v,ans:longint;
f,a:array[0..9,0..9] of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
begin
readln(n);
while true do
begin
readln(i,j,v);
if (i=0) and (j=0) and (v=0) then
break;
a[i,j] := v;
end;
//求解第一次
for i:=1 to n do
for j:=1 to n do
f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
ans := f[n,n];
//回溯走过的路置0
while true do
begin
a[i,j] := 0;
if (i=1) and (j=1) or (f[i,j]=0) then break;
if f[i-1,j]>f[i,j-1] then
dec(i)
else
dec(j);
end;
//求解第二次
for i:=1 to n do
for j:=1 to n do
f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
writeln(ans+f[n,n]);
end.
while true do
begin
a[i,j] := 0;
if (i=1) and (j=1) or (f[i,j]=0) then break;
if f[i-1,j]>f[i,j-1] then
dec(i)
else
dec(j);
end;
for i:=1 to n do
for j:=1 to n do
f[i,j] := max(f[i-1,j],f[i,j-1]) + a[i,j];
writeln(ans+f[n,n]);
end.