# ソースコード

```
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
ll n, t[20], s[20][20], dp[100000];
int main() {
cin >> n;
REPO(i, 99191) dp[i] = INF;
REP(i, n)cin >> t[i];
REP(i, n) REP(j, n) cin >> s[i][j];
REP(i, 1 << n) {
REP(j, n) {
if (!(i & 1 << j)) {
ll now = 0;
REP(k, n) {
if (i & 1 << k) {
now += s[k][j];
}
}
dp[i + (1 << j)] = min(dp[i + (1 << j)], dp[i] + t[j] - now);
}
}
}
cout << dp[(1 << n) - 1] << endl;
}
```