#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } constexpr ll inf = 1e+17; ll dp[100000][15]; int N, pow3[15], w[15], c[15][15]; ll func(int card){ int mask = 0, cnt = 0, twocnt = 0; for(int i = 0; i < N; ++i){ mask += w[i] * pow3[i]; cnt += w[i] > 0; twocnt += w[i] == 2; } if(dp[mask][card] != inf) return dp[mask][card]; if(mask != pow3[N] - 1 && cnt == 1 && twocnt == 1) return dp[mask][card]; if(cnt == 1) return dp[mask][card] = 0; ll res = inf; if(mask == pow3[N] - 1){ w[card] -= 2; for(int prev_card = 0; prev_card < N; ++prev_card){ if(prev_card == card) continue; chmin(res, func(prev_card) + c[prev_card][card]); } w[card] += 2; } w[card] -= 1; for(int prev_card = 0; prev_card < N; ++prev_card){ if(prev_card == card || w[prev_card] == 0) continue; chmin(res, func(prev_card) + c[prev_card][card]); } w[card] += 1; return dp[mask][card] = res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i = 0; i < N; ++i){ for(int j = 0; j < N; ++j){ cin >> c[i][j]; } } pow3[0] = 1; w[0] = 2; for(int i = 1; i <= 10; ++i){ pow3[i] = pow3[i - 1] * 3; w[i] = 2; } for(int mask = 0; mask < pow3[10]; ++mask){ for(int i = 0; i < 10; ++i){ dp[mask][i] = inf; } } ll ans = inf; for(int i = 0; i < N; ++i) chmin(ans, func(i)); cout << ans << endl; // for(int i = 0; i < 2; ++i){ // for(int mask = 0; mask < 9; ++mask){ // if(dp[mask][i] == inf) cout << "x "; // else cout << dp[mask][i] << ' '; // }cout << endl; // } return 0; }