例如:0,1,2,3
所有不重复排序为:
0,1,2,3
0,1,3,2
0,2,1,3
0,2,3,1
0,3,1,2
0,3,2,1
1,0,2,3
1,0,3,2
1,2,0,3
1,2,3,0
1,3,0,2
1,3,2,0
2,0,1,3
2,0,3,1
2,1,0,3
2,1,3,0
2,3,0,1
2,3,1,0
3,0,1,2
3,0,2,1
3,1,0,2
3,1,2,0
3,2,0,1
3,2,1,0求0,1,2,3…………,99,100 的所有排列。
所有不重复排序为:
0,1,2,3
0,1,3,2
0,2,1,3
0,2,3,1
0,3,1,2
0,3,2,1
1,0,2,3
1,0,3,2
1,2,0,3
1,2,3,0
1,3,0,2
1,3,2,0
2,0,1,3
2,0,3,1
2,1,0,3
2,1,3,0
2,3,0,1
2,3,1,0
3,0,1,2
3,0,2,1
3,1,0,2
3,1,2,0
3,2,0,1
3,2,1,0求0,1,2,3…………,99,100 的所有排列。
UP UP
UP UP UP
Dim tmp as long
tmp = 1
for i=1 to n
tmp = tmp* i
next
print cstr(tmp) & “种排列”
//不过所有的罗列出来,我可不太行了~~不过我知道的是用递归法
End Sub
N!=N*(N-1)*(N-2)*...*3*2*1
所以0,1,2,3一共4个数就是4*3*2*1=24种……
那0到100一共101个数,这个就多了……100*99*98*97*96*............*5*4*3*2*1=?????(不知道,电脑会不会死机?)楼主,真的要把他们排出来吗?
Option Explicit
Private dblCount As DoublePrivate Sub Form_Click()
Dim Data() As String
Dim i As Long
On Error Resume Next
i = CLng(InputBox("Enter N"))
If Err.Number <> 0 Then
Exit Sub
End If
ReDim Data(0 To i)
For i = LBound(Data) To UBound(Data)
Data(i) = CStr(i)
Next i
List1.Clear
dblCount = 0
Permutation Data
MsgBox dblCount
End Sub
Private Sub Permutation(DataSource() As String, _
Optional ByVal lngCalLen As Long, _
Optional blnFirst As Boolean = True, _
Optional lngStep = 1)
Dim lngLbound As Long
Dim lngUbound As Long
Dim i As Long
lngLbound = LBound(DataSource)
lngUbound = UBound(DataSource)
If blnFirst = True Then
If lngUbound < lngLbound Then
lngStep = -1
End If
If lngLbound = lngUbound Then
WriteData DataSource
Else
lngCalLen = lngLbound + lngStep
For i = lngLbound To lngUbound Step lngStep
Exchange DataSource(lngLbound), DataSource(i)
Call Permutation(DataSource, lngCalLen, False, lngStep)
Exchange DataSource(lngLbound), DataSource(i)
Next i
End If
Else
If lngCalLen = UBound(DataSource) Then
WriteData DataSource
Else
For i = lngCalLen To lngUbound Step lngStep
Exchange DataSource(lngCalLen), DataSource(i)
Call Permutation(DataSource, lngCalLen + lngStep, False, lngStep)
Exchange DataSource(lngCalLen), DataSource(i)
Next i
End If
End IfEnd SubPrivate Sub WriteData(Data() As String)
Dim strData As String
strData = Join(Data, " ")
dblCount = dblCount + 1
List1.AddItem Format(CStr(dblCount), "000") & ") " & strData
DoEvents
End SubPrivate Sub Exchange(strFirst As String, strSecond As String)
Dim strTmp As String
strTmp = strFirst
strFirst = strSecond
strSecond = strTmp
End SubPrivate Sub Form_Unload(Cancel As Integer)
End
End Sub