记录编号 |
6472 |
评测结果 |
AAAAAAAAAA |
题目名称 |
取数字问题 |
最终得分 |
100 |
用户昵称 |
maxiem |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.016 s |
提交时间 |
2008-11-02 13:38:35 |
内存使用 |
0.27 MiB |
显示代码纯文本
program number;
const
value=190;
var
table:array [1..20,1..20] of integer;
m,n,i,j,k:integer;
flag:boolean;
dp:array [0..20,0..20,-value..value] of boolean;
begin
fillchar (dp,sizeof(dp),0);
assign (input,'number.in');
reset (input);
readln (m,n);
for i:=1 to m do for j:=1 to n do read (table[i,j]);
close (input);
assign (output,'number.out');
rewrite (output);
dp[1,1,table[1,1]]:=true;
for i:=1 to m do for j:=1 to n do for k:=-value to value do begin
if dp[i-1,j,k] then dp[i,j,k+table[i,j]]:=true;
if dp[i,j-1,k] then dp[i,j,k+table[i,j]]:=true;
end;
flag:=false;
for i:=1 to value do if dp[m,n,i] then begin
writeln (i);
flag:=true;
break;
end;
if not(flag) then writeln (-1);
close (output);
end.