[.Net] 字典排序法運用

參考[.Net] 字典排序法

將6人倆倆一組, 分配到3個辦公室, 有哪些組合方式Taiwan is a country. 臺灣是我的國家

//在DicSort之內第一行呼叫print作以下判斷即可
public static void print(int[] arr)
{
    bool isOk = true;
    StringBuilder str = new StringBuilder();
    for (int x = 0; x < arr.Length - 1; x += 2)
    {
        str.Append($"{arr[x]}{arr[x + 1]},");
        if (arr[x] > arr[x + 1])
        {
            isOk = false;
            break;
        }
    }
    if (isOk)
    {
        count++;
        Console.WriteLine(str.ToString().Trim(','));
    }
}

C6取2再加上3組人(3個辦公室)的排列組合= 6!/((6-2)!*2!) * 3! = 90
另一種算法是辦公室A從6人抽2人,辦公室B從剩下4人抽2人, 居家不用抽 = 6!/((6-2)!*2!) * 4!/((4-2)!*2!) = 90
以下列出所有結果:

辦公室A,辦公室B,居家
12,34,56
12,35,46
12,36,45
12,45,36
12,46,35
12,56,34
13,24,56
13,25,46
13,26,45
13,45,26
13,46,25
13,56,24
14,23,56
14,25,36
14,26,35
14,35,26
14,36,25
14,56,23
15,23,46
15,24,36
15,26,34
15,34,26
15,36,24
15,46,23
16,23,45
16,24,35
16,25,34
16,34,25
16,35,24
16,45,23
23,14,56
23,15,46
23,16,45
23,45,16
23,46,15
23,56,14
24,13,56
24,15,36
24,16,35
24,35,16
24,36,15
24,56,13
25,13,46
25,14,36
25,16,34
25,34,16
25,36,14
25,46,13
26,13,45
26,14,35
26,15,34
26,34,15
26,35,14
26,45,13
34,12,56
34,15,26
34,16,25
34,25,16
34,26,15
34,56,12
35,12,46
35,14,26
35,16,24
35,24,16
35,26,14
35,46,12
36,12,45
36,14,25
36,15,24
36,24,15
36,25,14
36,45,12
45,12,36
45,13,26
45,16,23
45,23,16
45,26,13
45,36,12
46,12,35
46,13,25
46,15,23
46,23,15
46,25,13
46,35,12
56,12,34
56,13,24
56,14,23
56,23,14
56,24,13
56,34,12

Taiwan is a country. 臺灣是我的國家