记录编号 6050 评测结果 AAAAATTTTT
题目名称 取数字问题 最终得分 50
用户昵称 Gravatarrottenwood 是否通过 未通过
代码语言 Pascal 运行时间 5.002 s
提交时间 2008-10-30 12:58:32 内存使用 0.11 MiB
显示代码纯文本
program number;
type
shuzu=array[0..11,0..11] 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);
  begin
 if (x=m)and(y=n) then print(c)
    else
     begin
      if (x+1<=m) then search(x+1,y,c+s[x+1,y]);
      if (y+1<=n) then search(x,y+1,c+s[x,y+1]);
     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,s[1,1]);
if min=maxlongint then writeln('-1')
                  else writeln(min);
                  close(output);
end.