- 搭建双塔
- 2013-10-04 21:12:20 @
程序:
var
f:array [0..100,-2000..2000] of integer;// 塔1-塔2的塔1高
l:array [1..100] of integer;
n,i,j:integer;
function max(a,b,c:integer):integer;
begin
if a>b then
if a>c then
max:=a
else max:=c
else
if b>c then
max:=b
else max:=c;
end;
begin
readln(n);
for i:=1 to n do
read(l[i]);
for j:=-2000 to 2000 do
f[0,j]:=-20000;
f[0,0]:=0;
for i:=1 to n do
for j:=-2000 to 2000 do
f[i,j]:=max(f[i-1,j-l[i]]+l[i],f[i-1,j+l[i]],f[i-1,j]);
if f[n,0]=0 then
writeln('lmpossible')
else writeln(f[n,0]);
end.
3 条评论
-
LiuWeiMing1997 LV 8 @ 2016-12-20 17:33:05
= 0 也是算无解
-
2016-03-31 09:38:57@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 980 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 984 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #4: WrongAnswer, time = 0 ms, mem = 980 KiB, score = 0
测试数据 #5: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 984 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 984 KiB, score = 10
WrongAnswer, time = 15 ms, mem = 984 KiB, score = 90
我也没过第4个,估计有坑 -
2013-11-24 17:43:10@
估计第四个点是奇葩
我也没过
- 1