|
楼主 |
发表于 2013-8-27 21:19
|
显示全部楼层
- Function PermutDo6(ByVal m&, ByVal n&)
- Dim i&, j&, k&
- tms = Timer
-
- n = n - 1: ReDim a&(n)
- ReDim b(1 To m) As Boolean
- For j = 0 To n - 1
- a(j) = 1 + j
- b(1 + j) = True
- Next
-
- 'i = 0: j = n: k = 0
- Do
- For i = 1 To m
- If Not b(i) Then
- ' a(j) = i
- k = k + 1
- End If
- Next
-
- Do Until j = 0
- j = j - 1: i = a(j): b(i) = False
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- If j < n - 1 Then
- i = 0
- Do
- i = i + 1
- If Not b(i) Then
- j = j + 1: a(j) = i: b(i) = True
- If j = n - 1 Then Exit Do
- End If
- Loop
- End If
- j = n: Exit Do
- End If
- Next
- Loop
- Loop Until j = 0
- PermutDo6 = Format(Timer - tms, "0.0000s ") & " kagawa Do6 Permut(" & m & "," & n + 1 & ")= " & k
-
- End Function
- Function PermutDo5(ByVal m&, ByVal n&)
- Dim i&, j&, k&
- tms = Timer
-
- n = n - 1: ReDim a&(n)
- ReDim b(1 To m) As Boolean
- For j = 0 To n - 1
- a(j) = 1 + j
- b(1 + j) = True
- Next
-
- 'i = 0: j = n: k = 0
- Do
- For i = 1 To m
- If Not b(i) Then
- ' a(j) = i
- k = k + 1
- End If
- Next
-
- Do Until j = 0
- j = j - 1: i = a(j): b(i) = False
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- i = 0: Exit Do
- End If
- Next
- Loop
- If i Then Exit Do
-
- For j = j + 1 To n - 1
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- Exit For
- End If
- Next
- Next
- Loop
- PermutDo5 = Format(Timer - tms, "0.0000s ") & " kagawa Do5 Permut(" & m & "," & n + 1 & ")= " & k
-
- End Function
复制代码- Sub GetPermut_Mid6()
- Dim i&, ii&, j&, k&, l&, m&, n&, s$
- tms = Timer
-
- m = [a1].End(4).Row: sj = [a1].Resize(m): n = [b1]
- k = Application.Permut(m, n)
- ReDim jg1$(1 To k, 1 To 1): k = 0
-
- For j = 1 To m
- If Len(sj(j, 1)) > l Then l = Len(sj(j, 1))
- Next
- ReDim sj1$(1 To m)
- s = String(l, " ")
- For j = 1 To m
- sj1(j) = Right(s & sj(j, 1), l)
- Next
-
- n = n - 1: ReDim a&(n)
- ReDim b(1 To m) As Boolean
- s = String(l * n + l, " ")
- For j = 0 To n - 1
- a(j) = 1 + j
- b(1 + j) = True
- Mid(s, j * l + 1, l) = sj1(1 + j)
- Next
-
- 'i = 0: j = n: k = 0
- Do
- For i = 1 To m
- If Not b(i) Then
- ' a(j) = i
- Mid(s, j * l + 1, l) = sj1(i)
- k = k + 1
- jg1(k, 1) = s
- End If
- Next
- If s = "6543" Then Stop
- Do Until j = 0
- j = j - 1: i = a(j): b(i) = False
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- Mid(s, j * l + 1, l) = sj1(i)
- If j < n - 1 Then
- i = 0
- Do
- i = i + 1
- If Not b(i) Then
- j = j + 1: a(j) = i: b(i) = True
- Mid(s, j * l + 1, l) = sj1(i)
- If j = n - 1 Then Exit Do
- End If
- Loop
- End If
- j = n: Exit Do
- End If
- Next
- Loop
- Loop Until j = 0
- [b16] = Format(Timer - tms, "0.000s PermutDo6 ") & k
-
- If [c1] = "" And k < 65536 Then
- tms = Timer: [j:j] = "": [j1].Resize(k) = jg1: [j1].EntireColumn.AutoFit
- [b16] = [b16] & " " & Format(Timer - tms, "0.000s")
- End If
- Erase jg1
- End Sub
- Sub GetPermut_Mid5()
- Dim i&, ii&, j&, k&, l&, m&, n&, s$
- tms = Timer
-
- m = [a1].End(4).Row: sj = [a1].Resize(m): n = [b1]
- k = Application.Permut(m, n)
- ReDim jg1$(1 To k, 1 To 1): k = 0
-
- For j = 1 To m
- If Len(sj(j, 1)) > l Then l = Len(sj(j, 1))
- Next
- ReDim sj1$(1 To m)
- s = String(l, " ")
- For j = 1 To m
- sj1(j) = Right(s & sj(j, 1), l)
- Next
-
- n = n - 1: ReDim a&(n)
- ReDim b(1 To m) As Boolean
- s = String(l * n + l, " ")
- For j = 0 To n - 1
- a(j) = 1 + j
- b(1 + j) = True
- Mid(s, j * l + 1, l) = sj1(1 + j)
- Next
-
- 'i = 0: j = n: k = 0
- Do
- For i = 1 To m
- If Not b(i) Then
- ' a(j) = i
- Mid(s, j * l + 1, l) = sj1(i)
- k = k + 1
- jg1(k, 1) = s
- End If
- Next
- ' If s = "6543" Then Stop
-
- Do Until j = 0
- j = j - 1: i = a(j): b(i) = False
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- Mid(s, j * l + 1, l) = sj1(i)
- i = 0: Exit Do
- End If
- Next
- Loop
- If i Then Exit Do
-
- For j = j + 1 To n - 1
- For i = i + 1 To m
- If Not b(i) Then
- a(j) = i: b(i) = True
- Mid(s, j * l + 1, l) = sj1(i)
- Exit For
- End If
- Next
- Next
- Loop
- [b15] = Format(Timer - tms, "0.000s PermutDo5 ") & k
-
- If [c1] = "" And k < 65536 Then
- tms = Timer: [i:i] = "": [i1].Resize(k) = jg1: [i1].EntireColumn.AutoFit
- [b15] = [b15] & " " & Format(Timer - tms, "0.000s")
- End If
- Erase jg1
- End Sub
复制代码 |
|