记录编号 |
6329 |
评测结果 |
AAAAAAAAAA |
题目名称 |
取数字问题 |
最终得分 |
100 |
用户昵称 |
王瑞祥K |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.038 s |
提交时间 |
2008-10-31 22:29:05 |
内存使用 |
0.46 MiB |
显示代码纯文本
program number(input,output);
var
a:array[1..21,1..21]of integer;
f:array[1..21,1..21,-410..410]of boolean;
flag:array[1..21,1..21]of boolean;
i,j,k,m,n,l,p:longint;
find:boolean;
begin
assign(input,'number.in');assign(output,'number.out');
reset(input);rewrite(output);
readln(m,n);
for i:=1 to m do begin
for j:=1 to n do begin
read(a[i,j]); flag[i,j]:=false;
end;
readln;
end;
flag[1,1]:=true;
f[1,1,a[1,1]]:=true;
for i:=1 to m do
for j:=1 to n do
if flag[i,j]then begin
flag[i,j]:=false;
if(i+1<=m)and(j+1>n)then begin
for k:=-400 to 400 do
if f[i,j,k]then f[i+1,j,k+a[i+1,j]]:=true;
flag[i+1,j]:=true;
end;
if(i+1>m)and(j+1<=n)then begin
for k:=-400 to 400 do
if f[i,j,k]then f[i,j+1,k+a[i,j+1]]:=true;
flag[i,j+1]:=true;
end;
if(i+1<=m)and(j+1<=n)then begin
for k:=-400 to 400 do
if f[i,j,k]then begin
f[i+1,j,k+a[i+1,j]]:=true;
f[i,j+1,k+a[i,j+1]]:=true;
end;
flag[i+1,j]:=true;
flag[i,j+1]:=true;
end;
end;
find:=false;
for i:=1 to 400 do
if f[m,n,i]then begin
find:=true; break;
end;
if find then write(i) else write(-1);
close(input);close(output);
end.