记录编号 |
5985 |
评测结果 |
AAAAATTTTT |
题目名称 |
取数字问题 |
最终得分 |
50 |
用户昵称 |
E.M.B.E.R |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
5.003 s |
提交时间 |
2008-10-30 08:22:45 |
内存使用 |
8.50 MiB |
显示代码纯文本
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,a[1,1]);
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.