记录编号 6297 评测结果 AAAAAAAAAA
题目名称 取数字问题 最终得分 100
用户昵称 Gravatar辨机ZN 是否通过 通过
代码语言 Pascal 运行时间 0.016 s
提交时间 2008-10-31 20:14:55 内存使用 2.94 MiB
显示代码纯文本
program number(f1,f2);
 type
  zn=array [1..60,1..60,-410..410] of boolean;
  ka=array [1..60,1..60] of integer;
  da=array [1..60,1..60] of boolean;
 var
  c:zn; a:ka; f1,f2:text; flagx,flagy:boolean;
  i,j,k,m,n,l,p:longint; flag,flag2:da;
 begin
  assign(f1,'number.in'); reset(f1);
  assign(f2,'number.out'); rewrite(f2);
  readln(f1,m,n);
  for i:=1 to m do
   for j:=1 to n do
    read(f1,a[i,j]);
  for i:=1 to m do
   for j:=1 to n do flag[i,j]:=false;
  flag[1,1]:=true;
  c[1,1,a[1,1]]:=true;
  for i:=1 to m do
   for j:=1 to n do
   if flag[i,j] then
    begin
     flag[i,j]:=false;
     flagx:=true; flagy:=true;
     if i+1>m then flagx:=false;
     if j+1>n then flagy:=false;
     if (flagx)and(flagy=false) then
      begin
       for k:=-400 to 400 do
        if c[i,j,k] then c[i+1,j,k+a[i+1,j]]:=true;
       flag[i+1,j]:=true;
      end;
     if (flagx=false)and(flagy) then
      begin
       for k:=-400 to 400 do
        if c[i,j,k] then c[i,j+1,k+a[i,j+1]]:=true;
       flag[i,j+1]:=true;
      end;
     if (flagx)and(flagy) then
      begin
       for k:=-400 to 400 do
         if c[i,j,k] then
          begin
           c[i+1,j,k+a[i+1,j]]:=true;
           c[i,j+1,k+a[i,j+1]]:=true;
          end;
       flag[i+1,j]:=true;
       flag[i,j+1]:=true;
      end;
    end;
  for i:=1 to 400 do
   if c[m,n,i] then
    begin
     writeln(f2,i);
     close(f1); close(f2);
     halt;
    end;
  writeln(f2,-1);
  close(f1);
  close(f2);
 end.