比赛 |
noip-081029 |
评测结果 |
AWWWWTTTTT |
题目名称 |
取数字问题 |
最终得分 |
10 |
用户昵称 |
name:弓虽 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-10-29 21:07:03 |
显示代码纯文本
program number(input,output);
var
i,j,k:longint;
a:array [2..50000,1..10] of longint;
b:array [1..21] of longint;
n,m:longint;
s:longint;
ans:longint;
min:longint;
procedure find(x,y,ans,f:longint);
var
i,j,k:longint;
temp:longint;
begin
if (x=m) and (y=n) then begin
ans:=ans+a[x,y];
if (ans<min) then min:=ans;
end;
for k:= 1 to 2 do
begin
if (x<=m) and (y<=n) then begin
if k=2 then find(x+1,y,ans+a[x,y],1);
if k=1 then find(x,y+1,ans+a[x,y],1);
end;end;
end;
begin
s:=-1;
assign(input,'number.in');
assign(output,'number.out');
reset(input);
rewrite(output);
readln(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
ans:=a[1,1];
min:=maxlongint;
find(1,1,ans,1);
if (ans>=0) then writeln(min)
else writeln('-1');
close(input);
close(output);
end.