[1,1][2,2][3,3][4,4] // 1234
[1,1][2,2][3,4][4,3] // 1243
[1,1][2,3][3,2][4,4] // 1324
[1,1][2,4][3,2][4,3] // 1423
.....
其实就是求1\2\3\4的所有排列1,6,11,16
1,6,12,15
1,7,10,16
1,7,12,14
1,8,10,15
1,8,11,14
2,5,11,16
2,5,12,15
2,7,9,16
2,7,12,13
2,8,9,15
2,8,11,13
3,5,10,16
3,5,12,14
3,6,9,16
3,6,12,13
3,8,9,14
3,8,10,13
4,5,10,15
4,5,11,14
4,6,9,15
4,6,11,13
4,7,9,14
4,7,10,13private int[,] array = new int[,]{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}
};
private void Calc(int[] left, int[] right)
{
if (left.Length <= 0)
{
for (int i = 0; i < right.Length; i++)
{
if (i > 0) Console.Write(",");
Console.Write(array[i, right[i]]);
}
Console.WriteLine();
}
else
{
for (int i = 0; i < left.Length; i++)
{
int[] tempLeft = new int[left.Length - 1];
int k = 0;
for (int j = 0; j < left.Length; j++)
{
if (j != i)
{
tempLeft[k++] = left[j];
}
}
int[] tempRight = new int[right.Length + 1];
for (int j = 0; j < right.Length; j++)
tempRight[j] = right[j];
tempRight[right.Length] = left[i];
Calc(tempLeft, tempRight);
}
}
}private void button1_Click(object sender, EventArgs e)
{
Calc(new int[] { 0, 1, 2, 3 }, new int[] { });
}
[1,1][2,2][3,4][4,3] // 1243
[1,1][2,3][3,2][4,4] // 1324
[1,1][2,4][3,2][4,3] // 1423
.....
其实就是求1\2\3\4的所有排列1,6,11,16
1,6,12,15
1,7,10,16
1,7,12,14
1,8,10,15
1,8,11,14
2,5,11,16
2,5,12,15
2,7,9,16
2,7,12,13
2,8,9,15
2,8,11,13
3,5,10,16
3,5,12,14
3,6,9,16
3,6,12,13
3,8,9,14
3,8,10,13
4,5,10,15
4,5,11,14
4,6,9,15
4,6,11,13
4,7,9,14
4,7,10,13private int[,] array = new int[,]{
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}
};
private void Calc(int[] left, int[] right)
{
if (left.Length <= 0)
{
for (int i = 0; i < right.Length; i++)
{
if (i > 0) Console.Write(",");
Console.Write(array[i, right[i]]);
}
Console.WriteLine();
}
else
{
for (int i = 0; i < left.Length; i++)
{
int[] tempLeft = new int[left.Length - 1];
int k = 0;
for (int j = 0; j < left.Length; j++)
{
if (j != i)
{
tempLeft[k++] = left[j];
}
}
int[] tempRight = new int[right.Length + 1];
for (int j = 0; j < right.Length; j++)
tempRight[j] = right[j];
tempRight[right.Length] = left[i];
Calc(tempLeft, tempRight);
}
}
}private void button1_Click(object sender, EventArgs e)
{
Calc(new int[] { 0, 1, 2, 3 }, new int[] { });
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货