|
香川群子 发表于 2012-7-10 20:17 
结果组合实际上有个特点,第k列的元素永远只在第k列中出现。
因此,实际上组合总数=m^n
大师 结合所学 自己写的代码 请指教
Option Explicit
Private Type node
col As New Collection
End Type
Dim n_col As Integer, n_row&
Dim dic, x, y$, x1&
Private lie() As node
Sub a()
Dim n, m
n_col = [a1].End(xlToRight).Column
Set dic = CreateObject("Scripting.Dictionary")
n_row = [a1].End(xlDown).Row
x = 1: x1 = 1
ReDim lie(1 To n_col)
For n = 1 To n_col
With lie(n)
For m = 1 To n_row
.col.Add (Cells(m, n))
Next
End With
Next
End Sub
Sub b(x)
Dim num, i&, yy
For Each num In lie(x).col
If x < n_col Then
y = y & num
yy = num
x = x + 1
Call b(x)
x = x - 1
i = Len(yy)
y = Left(y, Len(y) - i)
Else: y = y & num
dic(x1) = y
x1 = x1 + 1
yy = num
i = Len(num)
y = Left(y, Len(y) - i)
End If
Next
End Sub
Sub c()
Call a
y = ""
Call b(1)
Dim n As Integer
Range("p1").Resize(dic.Count, 1) = Application.WorksheetFunction.Transpose(dic.items)
End Sub
|
|