记录编号 8194 评测结果 AAAAAAAAAA
题目名称 [BYVoid S3] 艾萨拉的激流 最终得分 100
用户昵称 Gravatarelysian 是否通过 通过
代码语言 Pascal 运行时间 5.378 s
提交时间 2008-11-13 11:52:42 内存使用 76.91 MiB
显示代码纯文本
program elysian;
const
fin='azshara.in';fout='azshara.out';
var
f:array[0..10005,0..1005] of longint;
a:array[0..10005,0..1005] of longint;
n,m,ans:longint;
f1,f2:text;

function max(a,b,c:longint):longint;
begin
if (a>=b)and(a>=c) then max:=a
else if (b>=a)and(b>=c) then max:=b
else if (c>=a)and(c>=b) then max:=c;
end;

procedure init;
var
i,j:longint;
begin
assign(f1,fin);reset(f1);
readln(f1,m,n);
for i:=1 to n do
for j:=1 to m do
read(f1,a[i,j]);
fillchar(f,sizeof(f),0);
for i:=1 to m do
f[1,i]:=a[1,i];
close(f1);
end;

procedure main;
var
i,j:longint;
begin
for i:=2 to n do
for j:=1 to m do
 if a[i,j]<>-1 then
  begin
   if  a[i-1,j-1]<>-1 then
    if f[i-1,j-1]+a[i,j]>f[i,j] then f[i,j]:=f[i-1,j-1]+a[i,j];
   if a[i-1,j]<>-1 then
    if f[i-1,j]+a[i,j]>f[i,j] then f[i,j]:=f[i-1,j]+a[i,j];
   if a[i-1,j+1]<>-1 then
    if f[i-1,j+1]+a[i,j]>f[i,j] then f[i,j]:=f[i-1,j+1]+a[i,j];

  end;

for i:=1 to m do
if (f[n,i]>ans)and(a[n,i]<>-1) then ans:=f[n,i];

assign(f2,fout);rewrite(f2);
writeln(f2,ans);
close(f2);

end;

begin
init;
main;
end.