ソースコード
#include<bits/stdc++.h>
using namespace std;
int N, a[20][20], t[20], temp[20][20];
int foo(int te[], int x){//cout<<endl<<x<<endl;
if(x >= N)return 0;
int ans = 10101010, te2[20] = {}, te3[]={}, co=0, te4;
for(int i = 0; i < N; i++){//cout<<te[i]<<endl;
te2[i]=te[i];
if(te[i]==1)te3[co++] = i;
}
for(int i = 0; i < N; i++){
if(te[i]==1)continue;
int ma = 0;
for(int j = 0; j < co; j++){//cout<<" "<<j<<" "<<i<<" "<<a[j][i]<<endl;
ma+=a[te3[j]][i];
}//cout<<endl;
te4 =t[i]-ma;
//cout<<te4<<" "<<t[i]<<" "<<i<<" "<<ma<<endl;
te2[i]=1;
ans = min(foo(te2, x+1)+te4, ans);
te2[i]=0;
}
return ans;
}
int main(){
cin>>N;
for(int i = 0; i < N; i++)cin>>t[i];
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
cin>>a[i][j];
}
}
/*for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
int ma = 0;
for(int k = 0; k < j; k++){
if(ma < a[k][j])ma=a[k][j];
}
}
}*/
int te[20] = {};
cout<<foo(te, 0)<<endl;
return 0;
}