新思路 不过为什么错了?

思路大概是这样

a数组 存的是可以到达的高度(2个同时 x y) boolean

sta 存的是可以到达的高度值 并扩展 

i第几个水晶快

j循环 扩张sta

大牛们 帮帮忙啊

type

jilu=record

x,y:integer;

end;

var

h:array[1..100] of integer; 

a:array[0 ..2000,0..2000] of boolean;

sta:array[1..2000000]of jilu;

i,j,k,c,m,t,temp:integer;

begin

fillchar(a,sizeof(a),false);

fillchar(h,sizeof(h),0);

temp:=0;

read(m);

readln;

for i:=1 to m do

read(h[i]);

a[0,0]:=true;

t:=1;

sta[1].x:=0;

sta[1].y:=0;

for i:=1 to m do

for j:=1 to t do

if a[sta[j].x,sta[j].y] then

begin

if not a[sta[j].x+h[i],sta[j].y] then

begin

inc(t);

sta[t].x:=sta[j].x+h[i];

sta[t].y:=sta[j].y;

a[sta[t].x,sta[t].y]:=true; // writeln(i,' ',t,' ',sta[t].x,' ',sta[t].y);

end;

if not a[sta[j].x,sta[j].y+h[i]] then

begin

inc(t);

sta[t].x:=sta[j].x;

sta[t].y:=sta[j].y+h[i]; // writeln(i,' ',t,' ',sta[t].x,' ',sta[t].y);

a[sta[t].x,sta[t].y]:=true;

end;

end;

temp:=0;

for i:=1 to 2000 do

if a then

if i>temp then

temp:=i;

if temp=0 then write('impossible')

else

write(temp);

end.

1 条评论

  • 1

信息

ID
1037
难度
6
分类
动态规划 | 背包 点击显示
标签
(无)
递交数
10534
已通过
2736
通过率
26%
被复制
15
上传者