比赛 noip-081029 评测结果 AAAAAWWWWW
题目名称 取数字问题 最终得分 50
用户昵称 Oo湼鞶oO 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-29 21:15:24
显示代码纯文本
{*******************************************}
{* Program name: number                    *}
{* Input file: number.in                   *}
{* Ouptut file: number.out                 *}
{* Date: 2008.10.29                        *}
{* Programmer: Peng Bo                     *}
{*******************************************}
program number;
type
  sz=array[1..10,1..10]of integer;
var
  s:sz;
  m,n,i:byte;
  g:integer;
  have_or_no_answers:boolean;
  f:text;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main(x,y:byte; l:integer);
begin
  if (x<>m)or(y<>n)
  then
  begin
    if y<n
    then
      main(x,y+1,l+s[x,y]);
    if x<m
    then
      main(x+1,y,l+s[x,y]);
  end
  else
    if (l+s[x,y]>0)and(l+s[x,y]<g)
    then
    begin
       g:=l+s[x,y];
       have_or_no_answers:=true;
    end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
  assign(f,'number.in');
  reset(f);
  readln(f,m,n);
  for i:=1 to m do
  begin
    for g:=1 to (n-1) do
      read(f,s[i,g]);
    readln(f,s[i,n]);
  end;
  close(f);
  {===========}
  have_or_no_answers:=false;
  g:=maxint;
  main(1,1,0);
  {===========}
  assign(f,'number.out');
  rewrite(f);
  if have_or_no_answers
  then
    write(f,g)
  else
    write(f,-1);
  close(f);
end.