var
q,a,fa,st,no :array[0..1000]of longint;
n,i,t,h,r :longint;
mark :array[0..100]of boolean;
flag :boolean;
procedure bfs;
begin
h:=0;r:=1;q[1]:=0;st[1]:=0;
while h
inc(h);
t:=n-q[h]-1;
if not mark[t] then
begin
inc(r);q[r]:=t;st[r]:=st[h]+1;fa[r]:=h;no[r]:=0;mark[t]:=true;
if t=n then exit;
end;
if q[h]>0 then
begin
t:=n-q[h]+1;
if not mark[t] then
begin
inc(r);q[r]:=t;st[r]:=st[h]+1;fa[r]:=h;no[r]:=1;mark[t]:=true;
if t=n then exit;
end;
end;
end;
end; procedure print(x:longint);
begin
if fa[x]<>1 then print(fa[x]);
flag:=false;
for i:=1 to n do
if (a[i]=no[x])and(not flag) then flag:=true
else a[i]:=1-a[i];
for i:=1 to n do write(a[i],' ');
writeln;
end;
begin
assign(input,'coin.in'); reset(input);
assign(output,'coin.out'); rewrite(output);
readln(n);
for i:=1 to n do a[i]:=0;
bfs;
writeln(st[r]);
print(r);
close(input);
close(output);
end.
给你提供一个思路:c[i,j]表示用 j 个能否达到 i 高度 部分代码: for i:=1 to n do
for j:=0 to s do
begin
if f[j] then
begin
if j+a[i]<=10000 then
begin
f[j+a[i]]:=true;
for k:=0 to 100 do
if c[j,k] then c[j+a[i],k+1]:=true;
end;
end;
end;
for i:=1 to 100 do
if c[s,i] then
begin
writeln(i);
break;
end;
for i:=100 downto 1 do
if c[s,i] then
begin
writeln(i);
break;
end; 剩下的自己写吧,对你有好处
大师。。。。。。