|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Dim value(5)
- Dim data(3)
- Dim arr(3)
- Dim ar(7)
- Dim c As Integer
- Sub main()
- c = 0
- For i = 1 To 6
- value(i - 1) = i * 100
- Next
- Call selectt(UBound(value) + 1, 4)
- End Sub
- Sub selectt(n, m) '6取4的组合
- For i = n To m Step -1
- arr(m - 1) = value(i - 1)
- If m > 1 Then
- Call selectt(i - 1, m - 1)
- Else
- For j = 0 To 3
- data(j) = arr(j)
- Next
- Call rank(0, 4) '4个数的全排列
- End If
- Next
- End Sub
- Sub rank(k, n) '全排列
- For i = k To n - 1
- Call swap(k, i, data)
- If i < n - 1 Then
- Call rank(k + 1, n)
- Else
- '去重没有写代码
-
- For j = 0 To 3 '填补中间数
- ar(2 * j) = data(j)
- ar(2 * j + 1) = 1200 - data(j) - data((j + 1) Mod 4)
- Next
- t = True
- For j = 0 To 7 '判断有无重复数字
- If UBound(Filter(ar, ar(j))) > 0 Then
- t = False
- Exit For
- End If
- Next
- If t Then '输出
- c = c + 1
- Cells(c, 1).Resize(, 8) = ar
- End If
- End If
- Call swap(k, i, data)
- Next
- End Sub
- Sub swap(x, y, data)
- temp = data(x)
- data(x) = data(y)
- data(y) = temp
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|