注册 登录
编程论坛 ASP技术论坛

全排列问题

anjincheng 发布于 2011-03-31 16:33, 384 次点击
各位老师:
    以下代码实现的是从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 编辑 ]
5 回复
#2
hams2011-03-31 16:55
看着眼花,也不明白你什么意思
#3
anjincheng2011-03-31 17:32
谢谢~
#4
hams2011-04-01 08:10
你的数有零当然从零排起来呀,不然还叫什么排列
#5
anjincheng2011-04-01 08:51
没有0,数组是从1开始的。

附件如下:
只有本站会员才能查看附件,请 登录
#6
dzt00012011-04-01 10:16
看看你的ccc(i)都等于什么了?aaa赋值后都没有用到

将ccc(i)=i改为ccc(i)=aaa(i)
1