记录编号 6352 评测结果 AAAAAAAAAA
题目名称 取数字问题 最终得分 100
用户昵称 GravatarMayLava 是否通过 通过
代码语言 Pascal 运行时间 0.013 s
提交时间 2008-11-01 10:52:11 内存使用 0.27 MiB
显示代码纯文本
program MayLava;
var
 a:array[1..20,1..20]of longint;
 scv:array[0..20,0..20,-190..190]of boolean;
 m,n,sum:longint;
procedure start;
 var
  f:text;
  i,j:longint;
 begin
  fillchar(a,sizeof(a),0);
  fillchar(scv,sizeof(scv),false);
  assign(f,'number.in');
  reset(f);
  readln(f,m,n);
  for i:=1 to m do begin
   for j:=1 to n do
    read(f,a[i,j]);
   readln(f);
  end;
  close(f);
  sum:=maxlongint;
  scv[1,1,a[1,1]]:=true;
 end;
procedure hunt;
 var
  i,j,k:longint;
 begin
  for i:=1 to m do begin
   for j:=1 to n do begin
    for k:=-190 to 190 do begin
     if scv[i-1,j,k] then scv[i,j,k+a[i,j]]:=true;
     if scv[i,j-1,k] then scv[i,j,k+a[i,j]]:=true;
    end;
   end;
  end;
 end;
procedure print;
 var
  f:text;
  i:longint;
 begin
  assign(f,'number.out');
  rewrite(f);
  for i:=1 to 190 do
   if scv[m,n,i] then begin
    writeln(f,i);
    close(f);
    halt;
   end;
  writeln(f,'-1');
  close(f);
 end;
BEGIN
 start;
 hunt;
 print;
END.