using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { int IdolCount = int.Parse(Reader.ReadLine()); this.Aisho = new int[IdolCount, IdolCount]; for (int i = 0; i < IdolCount; i++) { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < inpt.Length; j++) { this.Aisho[i, j] = inpt[j]; } } int ans = this.GetAns(0, 0); Console.WriteLine(ans); } private int GetAns(int idx, long flags) { long key = (long)1 << idx; if ((key & flags) > 0) { return GetAns(idx + 1, flags); } if (dic.ContainsKey(flags)) { return dic[flags]; } int ans = 0; for (int i = idx + 1; i < Aisho.GetLength(0); i++) { long pairKey = (long)1 << i; if ((flags & pairKey) > 0) { continue; } int ret = GetAns(idx + 1, flags + key + pairKey) + Aisho[idx, i]; ans = Math.Max(ret, ans); } dic[flags] = ans; return ans; } private Dictionary dic = new Dictionary(); private int[,] Aisho; public class Reader { public static bool IsDebug = false; private static String PlainInput = @" 6 -1 14 29 35 39 8 14 -1 35 41 34 3 29 35 -1 14 21 21 35 41 14 -1 12 42 39 34 21 12 -1 28 8 3 21 42 28 -1 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }