比赛 |
noip-081029 |
评测结果 |
AAAAAWWWWW |
题目名称 |
取数字问题 |
最终得分 |
50 |
用户昵称 |
MayLava |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-10-29 22:09:12 |
显示代码纯文本
program MayLava;
var
a:array[1..11,1..11]of longint;
m,n,sum:longint;
procedure start;
var
f:text;
i,j:longint;
begin
fillchar(a,sizeof(a),0);
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;
end;
procedure hunt(x,y,z:longint);
begin
if (x>m) or (y>n) then exit;
if (x=m) and (y=n) then begin
if (z>0) and (z<sum) then sum:=z;
exit;
end;
hunt(x+1,y,z+a[x+1,y]);
hunt(x,y+1,z+a[x,y+1]);
end;
procedure print;
var
f:text;
begin
assign(f,'number.out');
rewrite(f);
if sum=maxlongint then writeln(f,'-1')
else writeln(f,sum);
close(f);
end;
BEGIN
start;
hunt(1,1,a[1,1]);
print;
END.