比赛 noip-081029 评测结果 AAAAATTTTT
题目名称 取数字问题 最终得分 50
用户昵称 王瑞祥K 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-29 20:42:10
显示代码纯文本
program number(input,output);
type
 step=record
  xx,yy:integer;
 end;
const
 k:array[1..2]of step=((xx:1;yy:0),(xx:0;yy:1));
var
 a:array[1..20,1..20]of integer;
 n,m,max,s:integer;
procedure ini;
var i,j:integer;
begin
 assign(input,'number.in');assign(output,'number.out');
 reset(input);rewrite(output);
 readln(m,n);
 for i:=1 to m do begin
  for j:=1 to n do
   read(a[i,j]);
  readln;
 end;
 max:=10000;
 s:=0;
end;
procedure search(x,y:integer);
var i,j:integer;
begin
 if (x=m)and(y=n)then begin
  s:=s+a[x,y];
  if (s<max)and(s>0)then max:=s;
  s:=s-a[x,y];end
 else begin
  s:=s+a[x,y];
  for i:=1 to 2 do
   if (x+k[i].xx<=m)and(y+k[i].yy<=n)then
   search(x+k[i].xx,y+k[i].yy);
  s:=s-a[x,y];
 end;
end;
procedure print;
begin
 if max=10000 then write('-1')
 else write(max);
 close(input);close(output);
end;
begin
 ini;
 search(1,1);
 print;
end.