# ソースコード

```
#include <iostream>
#include <vector>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<deque>
#include<math.h>
#include<set>
#include<cstdio>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<stack>
#include<unordered_map>
#include<map>
#include <cassert>
#include<random>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define req(i,n) for(ll i = 1;i<=n;i++)
#define rrep(i,n) for(int i = n-1;i>=0;i--)
#define ALL(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
int main() {
int n; cin >> n; vector<int> t(n); vector<vector<int>> a(n, vector<int>(n));
rep(i, n) cin >> t[i];
rep(i, n) rep(j, n) cin >> a[i][j];
vector<int> dp(1 << n, 1e9); dp[0] = 0;
rep(bit, 1 << n) {
rep(j, n) {
if (!(bit >> j & 1)) {
int sum = 0;
rep(k, n) {
if (bit >> k & 1)sum += a[k][j];
}chmin(dp[bit | (1 << j)], dp[bit] + t[j] - sum);
}
}
}cout << dp[(1 << n)-1] << endl;
}
```