ソースコード
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');
const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin >> n;
vll t(n); REP(i, n) cin >> t[i];
vvll a(n, vll(n));
REP(i, n) REP(j, n) cin >> a[i][j];
vll dp(1LL<<n, HIGHINF); dp[0] = 0;
REP(i, n) dp[1<<i] = t[i];
rep(s, 1, 1LL<<n) {
REP(j, n) {
if (((s>>j)&1)==0) {
ll tmp = 0;
REP(k, n) if ((s>>k)&1) tmp += a[k][j];
chmin(dp[s^(1<<j)], dp[s] + t[j] - tmp);
}
}
}
cout << dp[(1<<n)-1] << '\n';
return 0;
}