比赛 noip-081029 评测结果 AWWWWTTTTT
题目名称 取数字问题 最终得分 10
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-29 19:47:33
显示代码纯文本
program number;
type
shuzu=array[1..10,1..10] of longint;
shuzu1=array[1..2] of integer;
var
s:shuzu;
xx,yy:shuzu1;
i,j,m,n,min:longint;
procedure print(c:longint);
  begin
  if (c<min)and(c>0) then min:=c;
  end;
procedure search(x,y,c:longint);
  var
  k,v:longint;
  begin
   for k:=1 to 2 do
   begin
   if (x+xx[k]<=m)and(y+yy[k]<=n) then
   begin
      x:=x+xx[k]; y:=y+yy[k];
      c:=c+s[x,y];
      if (x=m)and(y=n) then print(c)
                       else search(x,y,c);
                       end;
                       end;
                       end;
begin
assign(input,'number.in');reset(input);
assign(output,'number.out');rewrite(output);
readln(m,n);
xx[1]:=1; xx[2]:=0; yy[1]:=0; yy[2]:=1;
for i:=1 to m do
begin
 for j:=1 to n do
  read(s[i,j]);
  readln;
  end;
  min:=maxlongint;
search(1,1,0);
if min=maxlongint then writeln('-1')
                  else writeln(min);
                  close(output);
end.