wwx12 2014-03-04 04:46:57
点我顶贴
收藏
删除
program rq396;
const
maxn=1001;
var
a,f:array [-1..maxn,-1..maxn] of longint;
i,j,n,m,k,l,max:longint;
begin
read(n,m);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
f[1,1]:=a[1,1];
for i:=2 to n do
for j:=2 to m do
if a[i,j]=-1 then continue
else
begin
if (i-2>0) and (j-1>0) then
if a[i-2,j-1]<>-1 then
if f[i,j]<f[i-2,j-1]+a[i,j] then
f[i,j]:=f[i-2,j-1]+a[i,j];
if (i-1>0) and (j-2>0) then
if a[i-1,j-2]<>-1 then
if f[i,j]<f[i-1,j-2]+a[i,j] then
f[i,j]:=f[i-1,j-2]+a[i,j]
end;
max:=0;
for i:=1 to m do
if f[n,i]>max then max:=f[n,i];
for i:=1 to n do
if f[i,m]>max then max:=f[i,m];
if max>0 then writeln(max) else writeln('cannot arrive')
end.