比赛 |
noip-081029 |
评测结果 |
AAWWWTTTTT |
题目名称 |
取数字问题 |
最终得分 |
20 |
用户昵称 |
E.M.B.E.R |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-10-29 19:49:52 |
显示代码纯文本
program EmberAsh;
var
a:array[1..20000,1..10]of longint;
f:array[1..2000000]of longint;
i,j,k,m,n,max,head:longint;
procedure try(x,y,s:longint);
var
i,j,k,x1,y1,s1:longint;
begin
if (x=m)and(y=n) then
begin
inc(head);
f[head]:=s;
end
else
begin
if y+1<=n then//left
begin
x1:=x;
y1:=y+1;
s1:=s+a[x1,y1];
try(x,y+1,s1);
end;
if x+1<=m then//down
begin
x1:=x+1;
y1:=y;
s1:=s+a[x1,y1];
try(x+1,y,s1);
end;
end;
end;
BEGIN
assign(input,'number.in');reset(input);
assign(output,'number.out');rewrite(output);
readln(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
try(1,1,0);
max:=maxlongint;
for i:=1 to head do
if (f[i]>0)and(f[i]<max) then
max:=f[i];
if max=maxlongint then
writeln(-1)
else
writeln(max);
close(input);close(output);
END.