トップページに戻る    次のC#のサンプルへ    前のC#のサンプルへ

20-077 ポリックス(同一形複数)

問題

小田原充宏さんのポリックスの(同一形複数)問題を解きます。



10個のピースは下記となります。
各ピースは回転や裏返しても使えます。


Q6 同じ形を1度に3つ作る。


ソース

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static char[] PieceNameArr = { '1', '2', '3', '4', '5',
                                   '6', '7', '8', '9', 'A'};
    static int[] MensekiArr = { 6, 6, 6, 5, 5,
                                5, 4, 4, 4, 3};
    static int[] MaxHabaArr = { 4, 4, 3, 3, 3,
                                3, 3, 3, 3, 3};
    static int PieceNameArrUB = PieceNameArr.GetUpperBound(0);

    //ピースごとの配置候補
    static Dictionary<char, List<bool[,]>> HaitiKouhoListDict =
        new Dictionary<char, List<bool[,]>>();

    //組み合わせの状態Def
    struct CombinationJyoutaiDef
    {
        internal int CurrInd; //現在の配列のインデックス
        internal Dictionary<int, List<int>> SelectedIndListDict; //選択済インデックスListのDict
    }

    static void Main()
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        //ピースの組み合わせ候補を返す
        List<CombinationJyoutaiDef> PieceCombinationList = DerivePieceCombinationList();
        Console.WriteLine("ピースの組み合わせは{0}通りです", PieceCombinationList.Count);
        Console.WriteLine();

        foreach (char AnyPiece in PieceNameArr) {
            HaitiKouhoListDict[AnyPiece] = DeriveHaitiKouhoList(AnyPiece);
        }

        var sb = new System.Text.StringBuilder();
        int CombinationCnt = 0;

        //ピース配列から面積を求める
        Func<List<int>, int> FuncDeriveMensekiSum = (pTargetList) => pTargetList.Sum(X => MensekiArr[X]);

        foreach (CombinationJyoutaiDef EachCombination in PieceCombinationList) {
            sb.Length = 0;
            sb.AppendFormat("■■■■■組み合わせ{0}■■■■■", ++CombinationCnt);
            sb.AppendLine();

            for (int I = 1; I <= 3; I++) {
                sb.AppendFormat("{0}個目の組み合わせ", I);
                foreach (int EachInt in EachCombination.SelectedIndListDict[I]) {
                    sb.AppendFormat("{0},", PieceNameArr[EachInt]);
                }
                sb.AppendFormat("面積合計={0}",
                    FuncDeriveMensekiSum(EachCombination.SelectedIndListDict[I]));
                sb.AppendLine();
            }
            sb.AppendFormat("同一形複数を作成可能か検証中。経過時間={0}", sw.Elapsed);
            sb.AppendLine();
            Console.WriteLine(sb.ToString());

            if (CanCreateHukusuu(EachCombination.SelectedIndListDict))
                return;
        }
    }

    //ピースの組み合わせ候補のListを返す
    static List<CombinationJyoutaiDef> DerivePieceCombinationList()
    {
        var WillReturnList = new List<CombinationJyoutaiDef>();

        var stk = new Stack<CombinationJyoutaiDef>();
        CombinationJyoutaiDef WillPush;
        WillPush.CurrInd = 0;
        WillPush.SelectedIndListDict = new Dictionary<int, List<int>>();
        WillPush.SelectedIndListDict[1] = new List<int>();
        WillPush.SelectedIndListDict[2] = new List<int>();
        WillPush.SelectedIndListDict[3] = new List<int>();
        stk.Push(WillPush);

        while (stk.Count > 0) {
            CombinationJyoutaiDef Popped = stk.Pop();

            if (IsOKMensekiCombination(Popped.SelectedIndListDict)) {
                WillReturnList.Add(Popped);
            }

            if (Popped.CurrInd > PieceNameArrUB) continue;

            for (int I = Popped.CurrInd; I <= PieceNameArrUB; I++) {
                //使用済ピースは使用不可
                if (Popped.SelectedIndListDict[1].Contains(I)) continue;
                if (Popped.SelectedIndListDict[2].Contains(I)) continue;
                if (Popped.SelectedIndListDict[3].Contains(I)) continue;

                //3つの固まりに追加
                Action<int> wkAct = (pKeyVal) =>
                {
                    WillPush.CurrInd = I + 1;
                    WillPush.SelectedIndListDict =
                        new Dictionary<int, List<int>>(Popped.SelectedIndListDict);
                    WillPush.SelectedIndListDict[pKeyVal] =
                        new List<int>(Popped.SelectedIndListDict[pKeyVal]);
                    WillPush.SelectedIndListDict[pKeyVal].Add(I);
                    if (IsValidCombination(WillPush))
                        stk.Push(WillPush);
                };
                wkAct(1);
                wkAct(2);
                wkAct(3);

                //ピースを使わない経路
                WillPush.CurrInd = I + 1;
                WillPush.SelectedIndListDict = Popped.SelectedIndListDict;
                stk.Push(WillPush);
            }
        }
        return WillReturnList;
    }

    //有効な組み合わせかを返す
    static bool IsValidCombination(CombinationJyoutaiDef pCombinationJyoutaiDef)
    {
        List<int> IndList1 = pCombinationJyoutaiDef.SelectedIndListDict[1];
        List<int> IndList2 = pCombinationJyoutaiDef.SelectedIndListDict[2];
        List<int> IndList3 = pCombinationJyoutaiDef.SelectedIndListDict[3];

        //1つめの固まりの[0] < 2つめの固まりの[0] < 3つめの固まりの[0]
        if (IndList1.Count > 0 && IndList2.Count > 0)
            if (IndList1[0] > IndList2[0]) return false;
        if (IndList2.Count > 0 && IndList3.Count > 0)
            if (IndList2[0] > IndList3[0]) return false;

        //固まりごとで[0] < [1] < [2] < [3] < [n] として対称解の除外
        Predicate<List<int>> wkPred = (pIndList) =>
        {
            for (int I = 1; I <= pIndList.Count - 1; I++) {
                if (pIndList[I - 1] > pIndList[I])
                    return false;
            }
            return true;
        };
        if (wkPred(IndList1) == false) return false;
        if (wkPred(IndList2) == false) return false;
        if (wkPred(IndList3) == false) return false;
        return true;
    }

    //3つの固まりの面積合計がOKかを判定
    static bool IsOKMensekiCombination(Dictionary<int, List<int>> pSelectedIndListDict)
    {
        int[] wkSumArr = new int[4];
        for (int I = 1; I <= 3; I++) {
            foreach (int EachInd in pSelectedIndListDict[I]) {
                wkSumArr[I] += MensekiArr[EachInd];
            }
        }

        //固まりの面積合計が、3つとも0でないこと
        if (wkSumArr[1] == 0) return false;
        if (wkSumArr[2] == 0) return false;
        if (wkSumArr[3] == 0) return false;

        //3つの固まりの面積合計が、3つとも等しいこと
        if (wkSumArr[1] != wkSumArr[2]) return false;
        if (wkSumArr[1] != wkSumArr[3]) return false;
        return true;
    }

    //敷き詰めの状態Def
    struct ShikitumeJyoutaiDef
    {
        internal int Level;
        internal char[,] BanArr;
        internal int CurrX;
        internal int CurrY;
    }

    //選択済インデックスListのDictを引数として、同一形複数が可能かをチェック
    static bool CanCreateHukusuu(Dictionary<int, List<int>> pSelectedIndListDict)
    {
        var stk = new Stack<ShikitumeJyoutaiDef>();
        ShikitumeJyoutaiDef WillPush;

        int UB_X = 0;
        int UB_Y = 0;
        //1つめのListジェネリックの添え字に対応した長さを加算
        foreach (int EachInd in pSelectedIndListDict[1]) {
            UB_X += MaxHabaArr[EachInd] * 2;
            UB_Y += MaxHabaArr[EachInd];
        }

        WillPush.Level = 0;
        WillPush.BanArr = new char[UB_X + 1, UB_Y + 1];
        for (int X = 0; X <= UB_X; X++)
            for (int Y = 0; Y <= UB_Y; Y++)
                WillPush.BanArr[X, Y] = ' ';
        WillPush.CurrX = UB_X / 2;
        WillPush.CurrY = 0;
        stk.Push(WillPush);

        while (stk.Count > 0) {
            ShikitumeJyoutaiDef Popped = stk.Pop();

            //全ピースを使用しているかの判定
            if (Popped.Level == pSelectedIndListDict[1].Count) {

                char[,] wkSyukusyouArr = ArrSyukusyou(Popped.BanArr);

                char[,] Haiti2Arr = CanHaiti(pSelectedIndListDict[2], wkSyukusyouArr);
                if (Haiti2Arr == null) continue;

                char[,] Haiti3Arr = CanHaiti(pSelectedIndListDict[3], wkSyukusyouArr);
                if (Haiti3Arr == null) continue;

                Console.WriteLine("解を発見");

                Console.WriteLine("1つ目の配置");
                PrintAnswer(wkSyukusyouArr);

                Console.WriteLine("2つ目の配置");
                PrintAnswer(Haiti2Arr);

                Console.WriteLine("3つ目の配置");
                PrintAnswer(Haiti3Arr);
                return true;
            }

            //X座標の繰上げ処理
            if (Popped.CurrX > UB_X) {
                Popped.CurrX = 0;
                Popped.CurrY++;

                //ピースが配置されない行だったら枝切り
                bool HasPiece = false;
                for (int X = 0; X <= UB_X; X++) {
                    if (Popped.BanArr[X, Popped.CurrY - 1] != ' ') HasPiece = true;
                }
                if (HasPiece == false) continue;
            }

            //最終行を超えた場合
            if (Popped.CurrY > UB_Y) continue;

            //使用済のピース名の配列
            char[] UsedPieceArr = Popped.BanArr.Cast<char>().Distinct().ToArray();

            foreach (char AnyPiece in PieceNameArr) {
                //使用済ピースだったらContinue
                if (Array.IndexOf(UsedPieceArr, AnyPiece) >= 0) continue;

                //使用できないピースだったらContinue
                if (pSelectedIndListDict[1].Exists(
                    X => AnyPiece == PieceNameArr[X]) == false) continue;

                //ピースの配置候補リスト
                List<bool[,]> HaitiKouhoList = new List<bool[,]>();
                HaitiKouhoList.AddRange(HaitiKouhoListDict[AnyPiece]);

                //マス目にピースを埋めれない候補をRemove
                HaitiKouhoList.RemoveAll(X =>
                    CanFillPiece(X, Popped.CurrX, Popped.CurrY, Popped.BanArr, ' ') == false);

                //ピースを配置する経路のPush処理
                foreach (bool[,] AnyPieceMap in HaitiKouhoList) {
                    WillPush.Level = Popped.Level + 1;
                    WillPush.BanArr = (char[,])Popped.BanArr.Clone();
                    WillPush.CurrX = Popped.CurrX;
                    WillPush.CurrY = Popped.CurrY;

                    //配置済ピースに隣接していたら配置可
                    bool wkIsRinsetu = false;

                    for (int X = 0; X <= AnyPieceMap.GetUpperBound(0); X++) {
                        for (int Y = 0; Y <= AnyPieceMap.GetUpperBound(1); Y++) {
                            if (AnyPieceMap[X, Y] == false) continue;
                            WillPush.BanArr[Popped.CurrX + X, Popped.CurrY + Y] = AnyPiece;

                            if (IsRinsetu(Popped.CurrX + X, Popped.CurrY + Y, Popped.BanArr))
                                wkIsRinsetu = true;
                        }
                    }
                    if (WillPush.Level == 1 || wkIsRinsetu) stk.Push(WillPush);
                }
            }
            //ピースを配置しない経路のPush
            WillPush.Level = Popped.Level;
            WillPush.BanArr = Popped.BanArr;
            WillPush.CurrX = Popped.CurrX + 1;
            WillPush.CurrY = Popped.CurrY;
            stk.Push(WillPush);
        }

        return false;
    }

    //2次元配列の使用してない部分を縮小して返す
    static char[,] ArrSyukusyou(char[,] pTargetArr)
    {
        int XMin = pTargetArr.GetUpperBound(0), YMin = pTargetArr.GetUpperBound(1);
        int XMax = 0, YMax = 0;

        for (int X = 0; X <= pTargetArr.GetUpperBound(0); X++) {
            for (int Y = 0; Y <= pTargetArr.GetUpperBound(1); Y++) {
                if (pTargetArr[X, Y] == ' ') continue;
                if (XMin > X) XMin = X;
                if (YMin > Y) YMin = Y;
                if (XMax < X) XMax = X;
                if (YMax < Y) YMax = Y;
            }
        }

        char[,] WillReturnArr = new char[XMax - XMin + 1, YMax - YMin + 1];
        for (int X = 0; X <= WillReturnArr.GetUpperBound(0); X++) {
            for (int Y = 0; Y <= WillReturnArr.GetUpperBound(1); Y++) {
                WillReturnArr[X, Y] = pTargetArr[XMin + X, YMin + Y];
            }
        }

        return WillReturnArr;
    }

    //選択済インデックスListと縮小済配置を引数として、同一形複数が可能かをチェック
    static char[,] CanHaiti(List<int> pSelectedIndList, char[,] pBanArr)
    {
        int UB_X = pBanArr.GetUpperBound(0);
        int UB_Y = pBanArr.GetUpperBound(1);

        var stk = new Stack<ShikitumeJyoutaiDef>();
        ShikitumeJyoutaiDef WillPush;

        WillPush.Level = 0;
        WillPush.BanArr = new char[UB_X + 1, UB_Y + 1];
        for (int X = 0; X <= UB_X; X++) {
            for (int Y = 0; Y <= UB_Y; Y++) {
                char wkChar = pBanArr[X, Y];
                if (wkChar == ' ') WillPush.BanArr[X, Y] = ' ';
                else WillPush.BanArr[X, Y] = '?';
            }
        }
        WillPush.CurrX = WillPush.CurrY = 0;
        stk.Push(WillPush);

        while (stk.Count > 0) {
            ShikitumeJyoutaiDef Popped = stk.Pop();

            //クリア判定
            if (Popped.BanArr.Cast<char>().All(X => X != '?'))
                return Popped.BanArr;

            //X座標の繰上げ処理
            if (Popped.CurrX > UB_X) {
                Popped.CurrX = 0;
                Popped.CurrY++;
            }

            //最終行を超えた場合
            if (Popped.CurrY > UB_Y) continue;

            //使用済のピース名の配列
            char[] UsedPieceArr = Popped.BanArr.Cast<char>().Distinct().ToArray();

            foreach (char AnyPiece in PieceNameArr) {
                //使用済ピースだったらContinue
                if (Array.IndexOf(UsedPieceArr, AnyPiece) >= 0) continue;

                //使用できないピースだったらContinue
                if (pSelectedIndList.Exists(
                    X => AnyPiece == PieceNameArr[X]) == false) continue;

                //ピースの配置候補リスト
                List<bool[,]> HaitiKouhoList = new List<bool[,]>();
                HaitiKouhoList.AddRange(HaitiKouhoListDict[AnyPiece]);

                //現在のマス目が空きマスの場合は、マス目を埋める必要あり
                if (Popped.BanArr[Popped.CurrX, Popped.CurrY] == '?')
                    HaitiKouhoList.RemoveAll(X => X[0, 0] == false);

                //マス目にピースを埋めれない候補をRemove
                HaitiKouhoList.RemoveAll(X =>
                    CanFillPiece(X, Popped.CurrX, Popped.CurrY, Popped.BanArr, '?') == false);

                //ピースを配置する経路のPush処理
                foreach (bool[,] AnyPieceMap in HaitiKouhoList) {
                    WillPush.Level = Popped.Level + 1;
                    WillPush.BanArr = (char[,])Popped.BanArr.Clone();
                    WillPush.CurrX = Popped.CurrX;
                    WillPush.CurrY = Popped.CurrY;

                    for (int X = 0; X <= AnyPieceMap.GetUpperBound(0); X++) {
                        for (int Y = 0; Y <= AnyPieceMap.GetUpperBound(1); Y++) {
                            if (AnyPieceMap[X, Y] == false) continue;
                            WillPush.BanArr[Popped.CurrX + X, Popped.CurrY + Y] = AnyPiece;
                        }
                    }
                    stk.Push(WillPush);
                }

                //現在のマス目が空きマスでない場合は、ピースを配置しない経路のPush
                if (Popped.BanArr[Popped.CurrX, Popped.CurrY] != '?') {
                    WillPush.Level = Popped.Level;
                    WillPush.BanArr = Popped.BanArr;
                    WillPush.CurrX = Popped.CurrX + 1;
                    WillPush.CurrY = Popped.CurrY;
                    stk.Push(WillPush);
                }
            }
        }
        return null;
    }

    //ピース名を引数として、回転させた配置のListを返す
    static List<bool[,]> DeriveHaitiKouhoList(char pPieceName)
    {
        bool[,] wkArr = null;

        //■
        //■
        //■■
        //■■
        if (pPieceName == '1') {
            wkArr = new bool[2, 4];
            wkArr[0, 0] = true; wkArr[1, 0] = false;
            wkArr[0, 1] = true; wkArr[1, 1] = false;
            wkArr[0, 2] = wkArr[1, 2] = true;
            wkArr[0, 3] = wkArr[1, 3] = true;
        }

        //■
        //■
        //■
        //■■■
        if (pPieceName == '2') {
            wkArr = new bool[3, 4];
            wkArr[0, 0] = true; wkArr[1, 0] = wkArr[2, 0] = false;
            wkArr[0, 1] = true; wkArr[1, 1] = wkArr[2, 1] = false;
            wkArr[0, 2] = true; wkArr[1, 2] = wkArr[2, 2] = false;
            wkArr[0, 3] = wkArr[1, 3] = wkArr[2, 3] = true;
        }

        //■
        //■■■
        //■■
        if (pPieceName == '3') {
            wkArr = new bool[3, 3];
            wkArr[0, 0] = true; wkArr[1, 0] = wkArr[2, 0] = false;
            wkArr[0, 1] = wkArr[1, 1] = wkArr[2, 1] = true;
            wkArr[0, 2] = wkArr[1, 2] = true; wkArr[2, 2] = false;
        }

        // ■■
        //■■
        // ■
        if (pPieceName == '4') {
            wkArr = new bool[3, 3];
            wkArr[0, 0] = false; wkArr[1, 0] = wkArr[2, 0] = true;
            wkArr[0, 1] = wkArr[1, 1] = true; wkArr[2, 1] = false;
            wkArr[0, 2] = false; wkArr[1, 2] = true; wkArr[2, 2] = false;
        }

        //■■■
        // ■
        // ■
        if (pPieceName == '5') {
            wkArr = new bool[3, 3];
            wkArr[0, 0] = wkArr[1, 0] = wkArr[2, 0] = true;
            wkArr[0, 1] = false; wkArr[1, 1] = true; wkArr[2, 1] = false;
            wkArr[0, 2] = false; wkArr[1, 2] = true; wkArr[2, 2] = false;
        }

        //■■
        // ■
        // ■■
        if (pPieceName == '6') {
            wkArr = new bool[3, 3];
            wkArr[0, 0] = wkArr[1, 0] = true; wkArr[2, 0] = false;
            wkArr[0, 1] = false; wkArr[1, 1] = true; wkArr[2, 1] = false;
            wkArr[0, 2] = false; wkArr[1, 2] = wkArr[2, 2] = true;
        }

        //■
        //■
        //■■
        if (pPieceName == '7') {
            wkArr = new bool[2, 3];
            wkArr[0, 0] = true; wkArr[1, 0] = false;
            wkArr[0, 1] = true; wkArr[1, 1] = false;
            wkArr[0, 2] = wkArr[1, 2] = true;
        }

        // ■
        //■■
        //■
        if (pPieceName == '8') {
            wkArr = new bool[2, 3];
            wkArr[0, 0] = false; wkArr[1, 0] = true;
            wkArr[0, 1] = wkArr[1, 1] = true;
            wkArr[0, 2] = true; wkArr[1, 2] = false;
        }

        //■■■
        // ■
        if (pPieceName == '9') {
            wkArr = new bool[3, 2];
            wkArr[0, 0] = wkArr[1, 0] = wkArr[2, 0] = true;
            wkArr[0, 1] = false; wkArr[1, 1] = true; wkArr[2, 1] = false;
        }

        //■
        //■
        //■
        if (pPieceName == 'A') {
            wkArr = new bool[1, 3];
            wkArr[0, 0] = true;
            wkArr[0, 1] = true;
            wkArr[0, 2] = true;
        }

        return DeriveKaitenArrList(wkArr);
    }

    //配列を引数として、回転させた配列のリストをDistinctして返す
    static List<bool[,]> DeriveKaitenArrList(bool[,] pBaseArr)
    {
        var KaitenArrList = new List<bool[,]>();

        int BaseArrUB_X = pBaseArr.GetUpperBound(0);
        int BaseArrUB_Y = pBaseArr.GetUpperBound(1);

        for (int I = 1; I <= 8; I++) KaitenArrList.Add(null);
        for (int P = 0; P <= 6; P += 2) KaitenArrList[P] = new bool[BaseArrUB_X + 1, BaseArrUB_Y + 1];
        for (int P = 1; P <= 7; P += 2) KaitenArrList[P] = new bool[BaseArrUB_Y + 1, BaseArrUB_X + 1];

        for (int X = 0; X <= BaseArrUB_X; X++) {
            for (int Y = 0; Y <= BaseArrUB_Y; Y++) {
                bool SetVal = pBaseArr[X, Y];
                KaitenArrList[0][X, Y] = SetVal;
                KaitenArrList[1][Y, BaseArrUB_X - X] = SetVal;
                KaitenArrList[2][BaseArrUB_X - X, BaseArrUB_Y - Y] = SetVal;
                KaitenArrList[3][BaseArrUB_Y - Y, X] = SetVal;

                KaitenArrList[4][X, BaseArrUB_Y - Y] = SetVal;
                KaitenArrList[5][BaseArrUB_Y - Y, BaseArrUB_X - X] = SetVal;
                KaitenArrList[6][BaseArrUB_X - X, Y] = SetVal;
                KaitenArrList[7][Y, X] = SetVal;
            }
        }

        //Distinctする
        for (int I = KaitenArrList.Count - 1; 0 <= I; I--) {
            for (int J = 0; J <= I - 1; J++) {
                if (KaitenArrList[I].GetUpperBound(0) !=
                    KaitenArrList[J].GetUpperBound(0)) continue;
                if (KaitenArrList[I].GetUpperBound(1) !=
                    KaitenArrList[J].GetUpperBound(1)) continue;

                IEnumerable<bool> wkEnum1 = KaitenArrList[I].Cast<bool>();
                IEnumerable<bool> wkEnum2 = KaitenArrList[J].Cast<bool>();
                if (wkEnum1.SequenceEqual(wkEnum2) == false) continue;

                KaitenArrList.RemoveAt(I);
                break;
            }
        }
        return KaitenArrList;
    }

    //マス目にピースを埋めれるか
    static bool CanFillPiece(bool[,] pPieceMap, int pTargetX, int pTargetY, char[,] pBanArr, char pCharSpace)
    {
        if (pTargetX + pPieceMap.GetUpperBound(0) > pBanArr.GetUpperBound(0)) return false;
        if (pTargetY + pPieceMap.GetUpperBound(1) > pBanArr.GetUpperBound(1)) return false;

        for (int X = 0; X <= pPieceMap.GetUpperBound(0); X++) {
            for (int Y = 0; Y <= pPieceMap.GetUpperBound(1); Y++) {
                if (pPieceMap[X, Y] && pBanArr[pTargetX + X, pTargetY + Y] != pCharSpace)
                    return false;
            }
        }
        return true;
    }

    //配置済ピースに隣接しているか
    static bool IsRinsetu(int pTargetX, int pTargetY, char[,] pBanArr)
    {
        if (pTargetX + 1 <= pBanArr.GetUpperBound(0) && pBanArr[pTargetX + 1, pTargetY] != ' ') return true;
        if (0 <= pTargetX - 1 && pBanArr[pTargetX - 1, pTargetY] != ' ') return true;
        if (pTargetY + 1 <= pBanArr.GetUpperBound(1) && pBanArr[pTargetX, pTargetY + 1] != ' ') return true;
        if (0 <= pTargetY - 1 && pBanArr[pTargetX, pTargetY - 1] != ' ') return true;
        return false;
    }

    //解を出力
    static void PrintAnswer(char[,] pBanArr)
    {
        var sb = new System.Text.StringBuilder();
        for (int Y = 0; Y <= pBanArr.GetUpperBound(1); Y++) {
            for (int X = 0; X <= pBanArr.GetUpperBound(0); X++) {
                sb.Append(pBanArr[X, Y]);
            }
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
    }
}


実行結果

省略
■■■■■組み合わせ32■■■■■
1個目の組み合わせ4,面積合計=5
2個目の組み合わせ5,面積合計=5
3個目の組み合わせ6,面積合計=5
同一形複数を作成可能か検証中。経過時間=00:00:10.2039692

■■■■■組み合わせ33■■■■■
1個目の組み合わせ4,9,面積合計=9
2個目の組み合わせ5,8,面積合計=9
3個目の組み合わせ6,7,面積合計=9
同一形複数を作成可能か検証中。経過時間=00:00:10.2105566

解を発見
1つ目の配置
   9
 499
 449
44

2つ目の配置
   5
 555
 885
88

3つ目の配置
   7
 667
 677
66


解説

最初にピースの組み合わせ候補を求めてから
面積の合計が異なる組み合わせを除外して、
それから、13-04 Yyダブルデッカーのアルゴリズムを流用して、同一形で敷き詰め可能かを検証してます。