全排列问题
各位老师:以下代码实现的是从22个数中任选5个数进行全排列,运行后,结果总是从0开始全排列了(结果如下:)
0 1 2 3 4
0 1 2 3 5
0 1 2 3 6
.........
但我想让其从1开始排列(想得到如下结果:)
1 2 3 4 5
1 2 3 4 6
1 2 3 4 7
.........
请问各老师,怎么修改以下代码!谢谢诶!!
<%
aaa=Array(01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22)
countaaa=ubound(aaa)
m=0
n=5
redim bbb(m)
redim ccc(n)
for i=0 to n-1
ccc(i)=i
next
bbb(0)=ccc
response.write "<br>"&m&":"
for i=0 to n-1
response.write bbb(0)(i)&" "
next
m=m+1
while bbb(m-1)(0)<countaaa-n+1
redim PRESERVE bbb(m)
response.write "<br>"&m&":"
ccc(n-1)=ccc(n-1)+1
jinweixunhuan
bbb(m)=ccc
for i=0 to n-1
response.write bbb(m)(i)&" "
next
m=m+1
wend
sub jinweixunhuan()
for i=n-1 to 1 step -1
if ccc(i)>countaaa-n+1+i then
ccc(i-1)=ccc(i-1)+1
ccc(i)=-1
jinweixunhuan
end if
next
for i=1 to n-1
if ccc(i)=-1 then
ccc(i)=ccc(i-1)+1
end if
next
end sub
%>
[ 本帖最后由 anjincheng 于 2011-3-31 17:31 编辑 ]