#include #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; int main() { int N; cin >> N; int A[N][N]; rep(i, N) rep(j, N) cin >> A[i][j]; unordered_map dp; rep(k, N / 2) { if (k == 0) { for(int i = 1; i < N; i++) dp[1 | 1 << i] = A[0][i]; continue; } unordered_map ndp; int s = (1 << k) - 1; int x, y; for (int T = (1 << k) - 1; T < (1 << N - k); x = T & -T, y = T + x, T = (((T & ~y) / x) >> 1) | y) { int mask = s | T << k; int i = 0; while(mask & 1 << i) i++; for(int j = i + 1; j < N; ++j) { if (mask & 1 << j) continue; int nmask = mask | 1 << i | 1 << j; if (ndp.find(nmask) == ndp.end()) ndp[nmask] = dp[mask] + A[i][j]; else ndp[nmask] = max(ndp[nmask], dp[mask] + A[i][j]); } } swap(dp, ndp); } cout << dp[(1 << N) - 1] << endl; }