比赛 noip-081029 评测结果 AAWWWWEWWW
题目名称 取数字问题 最终得分 20
用户昵称 elysian 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-29 21:11:10
显示代码纯文本
program elysian;
const
fin='number.in';fout='number.out';
dx:array[1..2] of longint=(1,0);
dy:array[1..2] of longint=(0,1);
var
a:array[0..10,0..10] of longint;
n,m,min,ans:longint;
f1,f2:text;

procedure bj(a:longint);
begin
if (a<min)and(a>0) then min:=a;
end;

procedure dfs(x,y:longint);
var
i,x1,y1:longint;
begin

for i:=1 to 2 do
begin
   x1:=x+dx[i];y1:=y+dy[i];
   if (x1>=1)and(x1<=m)and(y1>=1)and(y1<=n) then
    begin
    ans:=ans+a[x1,y1];
    if (x1=m)and(y1=n) then bj(ans)
    else dfs(x1,y1);

    ans:=ans-a[x1,y1];
    end;
end;


end;

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


begin
init;
dfs(1,1);
assign(f2,fout);rewrite(f2);
if min<>maxlongint then writeln(f2,min)
else writeln(f2,-1);
close(f2);
end.