算法:DP
分析:一个背包问题,设f[i,j]表示其中一路兵选了i个,总血量为j这个状态能否成立,则f[i+1,j+a[i]]=f[i,j] or f[i+1,j+a[i]]。最后倒着找一个最大值即可
program Vijos1153;
const
maxn=200;
maxm=4060;
var
n,sum:longint;
a:array [0..maxn] of longint;
f:array [0..maxn,0..maxm] of boolean;
procedure init;
var
i:longint;
begin
sum:=0;
readln(n);
for i:=1 to n do
begin
readln(a[i]);
inc(sum,a[i]);
end;
end;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure main;
var
i,j,k:longint;
begin
f[0,0]:=true;
for i:=1 to n do
begin
for j:=(n shr 1) downto 0 do
begin
for k:=0 to 4040 do
f[j+1,k+a[i]]:=f[j+1,k+a[i]] or f[j,k];
end;
end;
end;
procedure outit;
var
i:longint;
begin
for i:=(sum shr 1) downto 0 do
begin
if f[n shr 1,i] then
begin
writeln(i,' ',sum-i);
exit;
end;
end;
end;
begin
assign(input,'VJ1153.in'); reset(input);
assign(output,'VJ1153.0out'); rewrite(output);
init;
main;
outit;
close(input); close(output);
end.