求助

第4个点

program vj1280;

var

a:array[1..100,1..100]of longint;

f:array[0..100,0..30,-1000..1000]of boolean;

i,j,k,l,m,n:longint;

procedure init;

begin

readln(n);

for i := 1 to n do

for j := 1 to i do

read(a);

for i := n-1 downto 1 do

for j := 1 to i do

read(a[2*n-i,j]);

end;

procedure work;

begin

fillchar(f,sizeof(f),false);

f[1,1,a[1,1]]:=true;

for i := 2 to n do

begin

for k := -900 to 900 do

if f[i-1,1,k+a] or f[i-1,1,k-a]

then f:=true;

for j := 2 to i-1 do

for k := -900 to 900 do

if f[i-1,j-1,k+a] or f[i-1,j-1,k-a] or

f[i-1,j,k+a] or f[i-1,j,k+a] then

f:=true;

for k := -900 to 900 do

if f[i-1,i-1,k+a] or f[i-1,i-1,k-a]

then f:=true;

end;

for i := n+1 to 2*n-1 do

for j := 1 to i do

for k := -900 to 900 do

if f[i-1,j,k+a] or f[i-1,j,k-a] or

f[i-1,j+1,k+a] or f[i-1,j+1,k+a] then

f:=true;

for i := 0 to 900 do

begin

if f[2*n-1,1,i] or f[2*n-1,1,-i] then

begin

writeln(i);

exit;

end;

end;

end;

begin

init;

work;

end.

0 条评论

目前还没有评论...

信息

ID
1280
难度
6
分类
动态规划 点击显示
标签
(无)
递交数
1118
已通过
331
通过率
30%
被复制
3
上传者