假设数组arr1(x)={1,2,3,2}
如何由数组arr1得到一个二维数组arr2
arr2(y,x)
{
0,0,0,0
0,0,0,1
0,0,0,2
0,0,1,0
0,0,1,1
0,0,1,2
0,0,2,0
.....
}
即二维数组每一行的值为一维数组每个值从0开始的排列组合,一维数组长度不一定是4,可能会更长。
假设数组arr1(x)={1,2,3,2}
如何由数组arr1得到一个二维数组arr2
arr2(y,x)
{
0,0,0,0
0,0,0,1
0,0,0,2
0,0,1,0
0,0,1,1
0,0,1,2
0,0,2,0
.....
}
即二维数组每一行的值为一维数组每个值从0开始的排列组合,一维数组长度不一定是4,可能会更长。
Module Module1
Sub Main()
Dim arr1() As Integer = {1,3,1,2}
Dim snm, v, i, j, t As Integer
snm = 1
For Each v in arr1
snm = snm * (v+1)
Next
Dim arr2(snm-1,arr1.Length-1) As Integer
For i = 0 To snm-1
t = 1
For j = arr1.Length-1 To 0 step -1
arr2(i,j) = (i\t) MOD (arr1(j)+1)
t = t * (arr1(j)+1)
Next
Next
For i = 0 To snm-1
For j = 0 To arr1.Length-1
Console.Write(arr2(i,j)&" ")
Next
Console.WriteLine()
Next
End Sub
End Module