组合问题(先提取数字+全组合) 原

t
tedzheng

1.  先从数列中选取所需要的值: A,B,C,D,E中选取A,B,C

程序Combine_n_?是抽取数值；Combine_n_F表示从前往后  | Combine_n_B表示从后往前

2. 做出所取值A,B,C的全部组合情况;ABC,ACB,BAC,BCA,CBA,CAB

程序Permute进行全组合

``````Public out, iOut
Public arr
Public Org
Public num
Public nMax

'Combination of n from M
Sub Combination_x_In_X()
Dim t
Dim i
Dim m
t = Timer

iOut = 0
m = 1
num = 3                 'Combination Number
nMax = 5                'Number of Range
ReDim Org(1 To nMax)       'Identify Data
'Read Data from Worksheet to Array
For i = 1 To nMax
Org(i) = Sheet1.Cells(1, i).Value
Next i

ReDim arr(1 To num)          'Identify temp array
ReDim out(1 To 100)          'Identify output array

'Combine_n_B nMax, num        'main program
Combine_n_F 1, 1           'main program

'output result
For i = 1 To iOut
m = m + 1
Sheet1.Cells(m, 6) = out(i)
Next i
Debug.Print Timer - t
End Sub

'Combine program
'from front to back
'm: range of Numer
'n: current input number
Sub Combine_n_F(m, n)
Dim i, j
For i = m To nMax           'Loop to range
arr(n) = Org(i)          'data into temp array
If n < num Then          'recursion: process next postion of data
Combine_n_F i + 1, n + 1
Else                    'exit
'        Array_In_Out arr
Permute arr, 1, num      'program
End If
Next i
End Sub

'Combine program
'from back to front
'm: range of Numer
'n: current input number
Sub Combine_n_B(m, n)
Dim i, j
For i = m To n Step -1
arr(n) = Org(i)         'data into temp array
If n > 1 Then           'recursion: process next postion of data
Combine_n_B i - 1, n - 1
Else                    'exit
Array_In_Out arr
'       Permute arr, 1, num      'program
End If
Next i
End Sub

'Convert the position
Sub Permute(arr, m, n)
Dim temp
Dim i&
If m = n Then
Array_In_Out arr    'data into output array
Exit Sub
Else
For i = m To n Step 1
temp = arr(m)     'switch
arr(m) = arr(i)
arr(i) = temp
Permute arr, m + 1, n
temp = arr(m)     'back
arr(m) = arr(i)
arr(i) = temp
Next i
End If
End Sub

'data into output array
'store as string
Sub Array_In_Out(arr)
Dim i
Dim Str\$
For i = 1 To UBound(arr)
Str = Str & arr(i)
Next i
iOut = iOut + 1
out(iOut) = Str
End Sub
``````

5个字母中抽取3个例子结果:

 ABC ACB BAC BCA CBA CAB ABD ADB BAD BDA DBA DAB ABE AEB BAE BEA EBA EAB ACD ADC CAD CDA DCA DAC ACE AEC CAE CEA ECA EAC ADE AED DAE DEA EDA EAD BCD BDC CBD CDB DCB DBC BCE BEC CBE CEB ECB EBC BDE BED DBE DEB EDB EBD CDE CED DCE DEC EDC ECD

t

tedzheng

python机器学习库keras——AutoEncoder自编码、特征压缩

luanpeng825485697
2018/05/01
0
0

int 支持转换为 int 类型的，仅有 、、，其他类型均不支持。 float -> int 会去掉小数点及后面的数值，仅保留整数部分。 str -> int 如果字符串中有数字(0-9)和正负号(+/-)以外的字符，就会报...

Shocker
2018/07/23
0
0
CS231n (winter 2016) : Assignment1（续）

Deepool
2016/06/26
0
0

2018/07/31
0
0

2018/07/20
0
0

Vert.x系列（二）--EventBusImpl源码分析

45分钟前
1
0
Perl - 获取文件项目

wffger

2
0
vue组件系列3、查询下载

2
0
java浅复制和深复制

woshixin

1
0
kubernetes 二进制包安装

Colben

10
0