#include #include #include #include using namespace std; void updmax(int &x, int y) { x = std::max(x, y); } int main() { int n; std::cin >> n; std::vector> cost(n, std::vector(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> cost[i][j]; } } constexpr int INF = 1e9; std::vector dp(1 << n, -INF); dp[0] = 0; std::vector ok(1 << n); ok[0] = true; for (int i = 1; i < 1 << n; i++) { ok[i] = !ok[i & i - 1]; } for (int i = 0; i < 1 << n; i++) { if (!ok[i]) { continue; } for (int j = 0; j < n; j++) { if (i >> j & 1) { continue; } for (int k = j + 1; k < n; k++) { if (i >> k & 1) { continue; } updmax(dp[i | 1 << j | 1 << k], dp[i] + cost[j][k]); } } } std::cout << dp[(1 << n) - 1] << std::endl; }