3 2 30 20 10 0 6 2 6 0 3 2 3 0 2 2 1 1 0 2 2 0 0 0
1 3 1 2
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int INF = 0x3f3f3f3f; 4 const int maxn = 20; 5 int e[maxn][maxn],d[maxn],val[maxn],n,m; 6 bool vis[maxn],us[maxn],ans[maxn]; 7 int prim(int s) { 8 memset(d,0x3f,sizeof d); 9 memset(us,false,sizeof us); 10 int sum = d[s] = 0; 11 while(true) { 12 int minV = INF,idx = -1; 13 for(int i = 0; i < n; ++i) 14 if(!us[i] && vis[i] && d[i] < minV) minV = d[idx = i]; 15 if(minV == INF || idx == -1) break; 16 us[idx] = true; 17 sum += minV; 18 for(int i = 0; i < n; ++i) { 19 if(!us[i] && vis[i] && d[i] > e[idx][i]) 20 d[i] = e[idx][i]; 21 } 22 } 23 return sum; 24 } 25 int wval,nval; 26 void dfs(int dep,int cnt,int nsum) { 27 if(cnt == m) { 28 int tmp = prim(dep - 1); 29 if(wval == INF || wval*nsum > tmp*nval) { 30 wval = tmp; 31 nval = nsum; 32 memcpy(ans,vis,sizeof vis); 33 } 34 return; 35 } 36 if(dep >= n) return; 37 vis[dep] = true; 38 dfs(dep+1,cnt+1,nsum+val[dep]); 39 vis[dep] = false; 40 dfs(dep+1,cnt,nsum); 41 } 42 int main() { 43 while(scanf("%d %d",&n,&m),n||m) { 44 for(int i = 0; i < n; ++i) 45 scanf("%d",&val[i]); 46 for(int i = 0; i < n; ++i) 47 for(int j = 0; j < n; ++j) 48 scanf("%d",e[i]+j); 49 memset(vis,false,sizeof vis); 50 wval = INF; 51 dfs(0,0,0); 52 bool flag = false; 53 for(int i = 0; i < n; ++i) 54 if(ans[i]) { 55 if(flag) putchar(' '); 56 flag = true; 57 printf("%d",i+1); 58 } 59 putchar('\n'); 60 } 61 return 0; 62 } 63 64 /* 65 3 2 66 30 20 10 67 0 6 2 68 6 0 3 69 2 3 0 70 71 2 2 72 1 1 73 0 2 74 2 0 75 76 0 0 77 */