# ソースコード

```
#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;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
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[16], a[16][16], dp[1<<16];
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];
rep(i, 0, 1<<n) dp[i] = INF;
dp[0] = 0;
rep(i, 0, 1<<n) {
rep(j, 0, n) {
if (!(i & (1 << j))) {
int tmp = t[j];
rep(k, 0, n) {
if (!(i & (1<<k))) tmp -= a[k][j];
}
chmin(dp[i+(1<<j)], dp[i]+tmp);
}
}
}
cout << dp[(1<<n)-1] << endl;
return 0;
}
```