讨论 / 为什么只有40分
996760929 2009-08-12 06:08:00
点我顶贴 收藏 删除
var

n,m,s,t,i,j:longint;

a:array[0..1001,0..1001]of longint;

f:array[-1..1002,-1..1002]of int64;

max:int64;

b:boolean;

function maxn(a,b:int64):int64;

begin

if a>b then exit(a)

else exit(b);

end;

begin

readln(n,m);

for i:=1 to n do

for j:=1 to m do

read(a[i,j]);

fillchar(f,sizeof(f),0);

for i:=1 to n do

begin

f[i,1]:=-maxlongint;

f[1,i]:=-maxlongint;

end;

f[1,1]:=a[1,1];

for i:=2 to n do

for j:=2 to m do

if a[i,j]<>-1 then begin

if a[i-1,j-2]=-1 then s:=0

else s:=f[i-1,j-2];

if a[i-2,j-1]=-1 then t:=0

else t:=f[i-2,j-1];

f[i,j]:=maxn(s,t)+a[i,j];

end;

max:=0;

for i:=1 to n do

if (f[i,m]>max)and(a[i,m]<>-1) then max:=f[i,m];

for i:=1 to m do

if (f[n,i]>max)and(f[n,i]<>-1) then max:=f[n,i];

if max<>0 then writeln(max)

else writeln(’cannot arrive.’);

end.

查看更多回复
提交回复