比赛 NOIP2008集训模拟4 评测结果 C
题目名称 艾萨拉的激流 最终得分 0
用户昵称 SMXX 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 11:13:01
显示代码纯文本
program df;
var
f1,f2:text;
a:array[1..1000]of longint;
f:array[0..1,1..1000] of longint;
m,ans,w,l,i,j,x,y,z:longint;
function max(x,y,z:longint):longint;
begin
max:=-3;
if x>max then max:=x;
if y>max then max:=y;
if z>max then max:=z;
end;

begin
assign(f1,'azshara.in');
assign(f2,'azshara.out');
reset(f1);
rewrite(f2);
readln(f1,w,l);
m:=0;
for i:= 1to w do begin f[0,i]:=0;f[1,i]:=0;a[i]:=0;end;
for i:= 1to w do begin read(f1,a[i]);
                      if a[i]>=0 then f[m,i]:=a[i]
                                 else f[m,i]:=-1;
                 end;
for j:=2 to l do  begin
 for i:= 1 to w do begin
 read(f1,a[i]);
 if (i-1>=1)and(a[i]>=0)and(f[m,i-1]>=0) then x:=f[m,i-1]+a[i]
                           else x:=-1;
 if (a[i]>=0)and(f[m,i]>=0) then y:=f[m,i]+a[i]
                            else y:=-1;
 if (a[i]>=0)and(i+1<=w)and(f[m,i+1]>=0)then z:=f[m,i+1]+a[i]
                          else z:=-1;
   f[1-m,i]:=max(x,y,z);
    end;
   m:=1-m;
   end;
  ans:=-1;
for i:= 1 to w do if f[m,i]>ans then ans:=f[m,i];
writeln(f2,ans);
close(f1);
close(f2);
end.