记录编号 |
6272 |
评测结果 |
AAAAAAAAAA |
题目名称 |
取数字问题 |
最终得分 |
100 |
用户昵称 |
zxc111 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.025 s |
提交时间 |
2008-10-31 19:39:31 |
内存使用 |
0.45 MiB |
显示代码纯文本
program ooo;
var
i,j,k,n,m,min:longint;
a:array[0..20,0..20,-400..400] of boolean;
b:array[1..20,1..20] of longint;
t:text;
begin
assign(t,'number.in');
reset(t);
readln(t,n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(t,b[i,j]);
readln(t);
end;
close(t);
a[0,0,0]:=true;
a[1,0,0]:=true;
a[0,1,0]:=true;
for j:=1 to n do
for k:=1 to m do
for i:=-390 to 390 do
begin
if a[j-1,k,i-b[j,k]]=true then a[j,k,i]:=true;
if a[j,k-1,i-b[j,k]]=true then a[j,k,i]:=true;
end;
min:=maxlongint;
for i:=1 to 400 do
if (a[n,m,i]=true)and(i<min) then min:=i;
assign(t,'number.out');
rewrite(t);
if min=maxlongint then write(t,-1) else
write(t,min);
close(t);
end.