不是VIP会员,不能显示答案

题目解答

题目:
var i,j,s:integer;
b :array[0..5] of integer;
begin
s:=1;
for i:=1 to 5 do b[i]:=i;
j:=1;
while j>0 do
begin
j:=5;
while (j>0) and (b[j]=10+j-5) do j:=j-1;
if j>0 then
begin
s:=s+1; b[j]:=b[j]+1;
for i:=j+1 to 5 do b[i]:=b[j]+i-j
end;
end;
writeln('s=',s);
end.

输出:s=252
考点: 0
分析: 排列组合的问题
解答: 从12345 排到 678910,
可以转化为以下代码:
var a,b,c,d,e,s:longint;
begin
  for a:=1 to 6 do
    for b:=a+1 to 7 do
      for c:=b+1 to 8 do
        for d:=c+1 to 9 do
          for e:=d+1 to 10 do
            begin
              inc(s);  
              writeln(s,' ',a,b,c,d,e);
            end;

end.
评论:
老师: 0