#include #include //小数点出力用 //cout << fixed << setprecision(10) << ans; #include #include #include #include #include #include #include #include using ll = long long; using namespace std; #define modPHash (ll)((1LL<<61)-1) #define modP (ll)998244353 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; if (N > 8)return 0; //愚直O(N!) int D[8][8]; for (int i = 0;i < N;i++) { for (int j = 0;j < N;j++) { cin >> D[i][j]; } } vectorA; for (int i = 1;i < N;i++) { A.push_back(i); } int ans = 1e9; do { int nowT = 0; int nowP = 0; int Score = 0; vectorT(N); for (int i = 0;i < N - 1;i++) { nowT += D[nowP][A[i]]; nowP = A[i]; Score += nowT; } ans = min(ans, Score); } while (next_permutation(A.begin(), A.end())); cout << ans; }