結果
問題 | No.519 アイドルユニット |
ユーザー |
![]() |
提出日時 | 2017-06-10 06:03:12 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 694 ms / 1,000 ms |
コード長 | 3,082 bytes |
コンパイル時間 | 1,767 ms |
コンパイル使用メモリ | 108,416 KB |
実行使用メモリ | 185,728 KB |
最終ジャッジ日時 | 2024-10-02 13:35:16 |
合計ジャッジ時間 | 8,494 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;for (int K = 0; K <= N - 1; K++) {//使用済ならContinueif ((J & DeriveBitPos(K)) > 0)continue;for (int L = K + 1; L <= N - 1; L++) {//使用済ならContinueif ((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;}//Breakして、最小の人番号からペアを作成するようにするbreak;}}PrevDP = CurrDP;}Console.WriteLine(PrevDP[UB]);}//人番号を引数として対応するビット位置を返すstatic int DeriveBitPos(int pHitoNo){return 1 << pHitoNo;}}