i,j,n,m,t:longint;
function ab(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do read(a[i,j]);
readln;
end; t:=0; f[1,1]:=a[1,1];
fillchar(f,sizeof(f),0);
for i:=2 to n do
for j:=2 to m do
if (a[i,j]<>-1)and((f[i-1,j-2]>0)or(f[i-2,j-1]>0)) then begin
f[i,j]:=ab(f[i-1,j-2],f[i-2,j-1])+a[i,j]; write('*** '); end;
for i:=1 to n do if f[i,m]>t then t:=f[i,m];
for i:=1 to m do if f[n,i]>t then t:=f[n,i];
if t>0 then writeln(t) else writeln('cannot arrive.');
readln;
end.
var a,f:array [0..1000,0..1000] of longint;
i,j,n,m,t:longint;
function ab(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do read(a[i,j]);
readln;
end; t:=0; f[1,1]:=a[1,1];
fillchar(f,sizeof(f),0);
for i:=2 to n do
for j:=2 to m do
if (a[i,j]<>-1)and((f[i-1,j-2]>0)or(f[i-2,j-1]>0)) then
f[i,j]:=ab(f[i-1,j-2],f[i-2,j-1])+a[i,j];
for i:=1 to n do if f[i,m]>t then t:=f[i,m];
for i:=1 to m do if f[n,i]>t then t:=f[n,i];
if t>0 then writeln(t) else writeln('cannot arrive.');
readln;
end.
f[1,1]:=a[1,1];
fillchar(f,sizeof(f),0);
先后顺序反了,冤那......折腾了20分钟...