讨论 / 为什么只40分。。。。。
wower 2009-09-16 03:12:00
点我顶贴 收藏 删除
Program rq396;

const d=1000;

Var a,f:array[-10..d,-10..d]of longint;

z:array[1..d,1..d]of integer;

n, m,i,j,k,l,p1,q1,p2,q2,max:longint;

bo:boolean;

Begin

readln(n,m);

For i:=1 to n do

begin

For j:=1 to m do

read(a[i,j]);

readln;

end;

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

For i:=2 to n do

For j:=2 to m do

Begin

If a[i,j]<>-1 then

begin

p1:=i-1;

q1:=j-2;

p2:=i-2;

q2:=j-1;

If (p1>0)and(q1>0)and(a[p1,q1]<>-1) then

f[i,j]:=f[p1,q1]+a[i,j];

If (p2>0)and(q2>0)and(a[p2,q2]<>-1) then

if f[i,j]<a[i,j]+f[p2,q2]

then f[i,j]:=f[p2,q2]+a[i,j];

End;

End;

bo:=false;

For i:=1 to n do

For j:=m-1 to m do

begin

If a[i,j]<>-1 then bo:=true;

If max<f[i,j] then max:=f[i,j]

end;

For i:=n-1 to n do

For j:=1 to m do

Begin

If a[i,j]<>-1 then bo:=true;

If max<f[i,j] then max:=f[i,j];

end;

If not bo then begin

write(’cannot arrive’);

exit;

end;

write(max);

end.

查看更多回复
提交回复