记录编号 |
6346 |
评测结果 |
AAAAAAAAAA |
题目名称 |
取数字问题 |
最终得分 |
100 |
用户昵称 |
elysian |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.020 s |
提交时间 |
2008-11-01 10:05:41 |
内存使用 |
0.44 MiB |
显示代码纯文本
program elysian;
const
fin='number.in';fout='number.out';
var
f:array[0..20,0..20,-390..390] of boolean;
a:array[1..20,1..20] of longint;
flag:boolean;
n,m,t1,t2:integer;
f1,f2:text;
procedure init;
var i,j:longint;
begin
assign(f1,fin);reset(f1);
readln(f1,n,m);
for i:=1 to n do
for j:=1 to m do
read(f1,a[i,j]);
t2:=(n+m-1)*10;
t1:=-t2;
close(f1);
assign(f2,fout);rewrite(f2);
end;
procedure main;
var
i,j,k:longint;
begin
for i:=1 to n do
for j:=1 to m do
begin
if (i=1)and(j=1) then continue;
for k:=t1 to t2 do
begin
if f[i-1,j,k-a[i,j]]=true then f[i,j,k]:=true;
if f[i,j-1,k-a[i,j]]=true then f[i,j,k]:=true;
end;
end;
for i:=t1 to t2 do
if (f[n,m,i]=true)and(i>0) then begin writeln(f2,i);flag:=true;break;end;
end;
begin
init;
f[1,1,a[1,1]]:=true;
main;
if flag=false then writeln(f2,-1);
close(f2);
end.