ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, T[16], A[16][16], dp[1<<16];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, N) cin >> T[i];
rep(i, 0, N) rep(j, 0, N) cin >> A[i][j];
rep(msk, 0, 1 << N) dp[msk] = inf;
dp[0] = 0;
rep(msk, 0, 1 << N) rep(i, 0, N) if (!(msk & (1 << i))) {
int t = T[i];
rep(j, 0, N) if (msk & (1 << j)) t -= A[j][i];
chmin(dp[msk + (1 << i)], dp[msk] + t);
}
cout << dp[(1 << N) - 1] << endl;
}