#include #include #include #include #include #include #include #include #include #include #include #include #include #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i16 = short; using i64 = long long; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; void solve() { const int N_MAX = 24; int N; while (~scanf("%d", &N)) { int cost[N_MAX][N_MAX]; rep(i, N) rep(j, N) scanf("%d", &cost[i][j]); unordered_map umap[2]; auto& curr = umap[0], &next = umap[1]; curr.reserve(1 << 15), next.reserve(1 << 15); curr[(u64(1) << N) - 1] = 0; rep(i, N / 2) { next.clear(); for (auto it : curr) { int state, sum; tie(state, sum) = it; int i = __builtin_ctz(state); for (int s = state & (state - 1), t = s; t; t &= t - 1) { int j = __builtin_ctz(t); auto& v = next[s ^ (1 << j)]; v = max(v, sum + cost[i][j]); } } swap(curr, next); } printf("%d\n", curr[0]); } } int main() { clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }