# ソースコード

```
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int n, t[20], a[20][20], dp[1<<17][20], start;
int solve(int S, int v) {
if (dp[S][v] >= 0) return dp[S][v];
if (S == (1<<n)-1 && start == v) return dp[S][v] = 0;
int res = INF;
rep(u, 0, n) {
if (!(S>>u & 1))
res = min(res, solve(S|1<<u, u) + t[u] - a[v][u]);
}
return dp[S][v] = res;
}
int main() {
ios::sync_with_stdio ( false );
cin.tie ( 0 );
cin >> n;
rep(i, 0, n) cin >> t[i];
rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
memset(dp, -1, sizeof(dp));
int ans = INF;
rep(i, 0, n) {
start = i;
ans = min(ans, solve(0, i));
}
cout << ans << endl;
return 0;
}
```