积木城堡
来源:vijos P1059
【问题描述】
任务:
【输入文件】
【输出文件】
【输入样例】
2
2 1 –1
3 2 1 -1
【输出样例】
3
============================
================================
{
ID:jie19952
PROG:
LANG:PASCAL
}
//type
//re=record
//num:longint;
//x:array[1..101]of longint;
//end;
var
n,t:longint;
f:array[1..100,0..10000]of boolean;
a:array[0..101]of longint;
procedure init;
begin
assign(input,'p1059.in');
assign(output,'p1059.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
function pd(duibi:longint):boolean;
var
i:longint;
begin
pd:=true;
for i:=1 to n do
if not f[i,duibi] then exit(false);
end;
procedure main;
var
i,j,k:longint;
ans:longint;
begin
readln(n);
fillchar(a,sizeof(a),0);
//fillchar(f_last,sizeof(f_last),false);
fillchar(f,sizeof(f),false);
for i:=1 to n do
begin
//f_now[0]:=true;
f[i,0]:=true;
t:=1;
read(a[t]);
while a[t]<>-1 do
begin
inc(t);
read(a[t]);
end;
dec(t);
for j:=1 to t do
for k:=10000-a[j] downto 0 do
if f[i][k] then
begin
f[i][k+a[j]]:=true;
end;
end;
for i:=10000 downto 0 do
if pd(i) then
begin
writeln(i);
break;
end;
end;
begin
init;
main;
terminate;
end.