#include #include #include #define rep(i, j, n) for (int i = (j); i < (n); ++i) using namespace std; using ll = long long; constexpr ll INF = 1LL << 60; void chmin(ll& a, ll b) { if (a > b) a = b; } int n, a[10][10], p3[10], state[10]; void get_state(int S) { for (int i = 0; i < n; ++i) { state[i] = S % 3; S /= 3; } } int main() { cin >> n; rep(i, 0, n) rep(j, 0, n) cin >> a[i][j]; p3[0] = 1; rep(i, 0, n + 1) p3[i + 1] = p3[i] * 3; vector> dp(n, vector(p3[n], INF)); rep(i, 0, n) dp[i][p3[i]] = 0; rep(S, 0, p3[n]) { get_state(S); rep(from, 0, n) { if (dp[from][S] == INF || state[from] == 0) continue; rep(to, 0, n) { if (from == to || state[to] == 2) continue; chmin(dp[to][S + p3[to]], dp[from][S] + a[from][to]); } } } ll ans = INF; rep(i, 0, n) chmin(ans, min(dp[i][p3[n] - 1], dp[i][p3[n] - 1 - p3[i]])); cout << ans << '\n'; return 0; }