比赛 |
20120706 |
评测结果 |
ATTTTTTTTA |
题目名称 |
排队 |
最终得分 |
20 |
用户昵称 |
CC |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-06 11:43:32 |
显示代码纯文本
#include <cstdio>
#include <algorithm>
#define INF 1000000000
int n,K,tmp,ans;
int h[1005],t[1005][1005],a[1005];
bool done[1005];
void dfs(int u,int H) {
if (u > n) {
ans = std::min(ans,tmp);
return;
}
for (int i = 2;i <= n;i++)
if (!done[i]) {
if (H - h[i] >= K) return;
tmp += t[a[u - 1]][i];
a[u] = i;
done[i] = 1;
dfs(u + 1,std::max(H,h[i]));
done[i] = 0;
tmp -= t[a[u - 1]][i];
}
}
int main() {
freopen("queuea.in","r",stdin);
freopen("queuea.out","w",stdout);
scanf("%d%d", &n, &K);
int minl = INF;
for (int i = 1;i <= n;i++) {
scanf("%d", &h[i]);
if (h[i] < minl) {
minl = h[i];
a[1] = i;
}
}
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++) scanf("%d", &t[i][j]);
tmp = 0;
ans = INF;
dfs(2,h[a[1]]);
printf("%d\n", ans);
return 0;
}