- 搭建双塔
- 2016-01-31 21:31:31 @
program tower;
var
f:array[0..101,0..2001] of longint;
h:array[0..100] of longint;
i,j,n,s:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
begin
readln(n);
for i:=1 to n do
begin
read(h[i]);
s:=s+h[i];
end;
for i:=0 to n do
begin
for j:=0 to s do
f[i,j]:=-maxlongint;
end;
f[0,0]:=0;
for i:=1 to n do
begin
for j:=s downto 0 do
begin
if j<=h[i] then
f[i,j]:=max(f[i-1,j],max(f[i-1,h[i]-j]+j,f[i-1,j+h[i]]));
if j>h[i] then
f[i,j]:=max(f[i-1,j],max(f[i-1,j+h[i]],f[i-1,j-h[i]]+h[i]))
end;
end;
if f[n,0]>0 then write(f[n,0])
else write('Impossbile');
end.
2 条评论
-
Administrator2004 LV 7 @ 2017-07-14 08:20:26
<?php
-
2016-01-31 21:41:34@
求大犇帮忙
- 1