結果
| 問題 | 
                            No.519 アイドルユニット
                             | 
                    
| コンテスト | |
| ユーザー | 
                             明智重蔵
                         | 
                    
| 提出日時 | 2017-06-10 07:11:28 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 755 ms / 1,000 ms | 
| コード長 | 2,954 bytes | 
| コンパイル時間 | 969 ms | 
| コンパイル使用メモリ | 115,060 KB | 
| 実行使用メモリ | 178,436 KB | 
| 最終ジャッジ日時 | 2024-10-02 13:35:31 | 
| 合計ジャッジ時間 | 8,862 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static string InputPattern = "InputX";
    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();
        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("-1 16 15 38");
            WillReturn.Add("16 -1 22 17");
            WillReturn.Add("15 22 -1 19");
            WillReturn.Add("38 17 19 -1");
            //60
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6");
            WillReturn.Add("-1 14 29 35 39 8");
            WillReturn.Add("14 -1 35 41 34 3");
            WillReturn.Add("29 35 -1 14 21 21");
            WillReturn.Add("35 41 14 -1 12 42");
            WillReturn.Add("39 34 21 12 -1 28");
            WillReturn.Add("8 3 21 42 28 -1");
            //116
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();
        int N = int.Parse(InputList[0]);
        var FArrList = new List<int[]>();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            FArrList.Add(wkArr);
        }
        int UB = (1 << N) - 1;
        //相性度合計の最大値[登場した人のBit位置]なDP表
        var PrevDP = new Nullable<int>[UB + 1];
        PrevDP[0] = 0;
        //ペアの作成でループ
        for (int I = 1; I <= N / 2; I++) {
            var CurrDP = new Nullable<int>[UB + 1];
            for (int J = 0; J <= UB; J++) {
                if (PrevDP[J].HasValue == false) continue;
                int K;
                for (K = 0; K <= N - 1; K++) {
                    //使用済ならContinue
                    if ((J & DeriveBitPos(K)) > 0)
                        continue;
                    break;
                }
                for (int L = K + 1; L <= N - 1; L++) {
                    //使用済ならContinue
                    if ((J & DeriveBitPos(L)) > 0)
                        continue;
                    int NewJ = J;
                    NewJ |= DeriveBitPos(K);
                    NewJ |= DeriveBitPos(L);
                    int NewVal = PrevDP[J].Value + FArrList[K][L];
                    if (CurrDP[NewJ].HasValue && NewVal <= CurrDP[NewJ])
                        continue;
                    CurrDP[NewJ] = NewVal;
                }
            }
            PrevDP = CurrDP;
        }
        Console.WriteLine(PrevDP[UB]);
    }
    //人番号を引数として対応するビット位置を返す
    static int DeriveBitPos(int pHitoNo)
    {
        return 1 << pHitoNo;
    }
}
            
            
            
        
            
明智重蔵