You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
860 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 25;
int a[N][N]; // 记录用户输入的数据工作i由j这个人来完成需要的时间
bool st[N]; // 是不是已经分配完
int n, ans = INF;
void dfs(int step, int sum) {
if (step == n + 1) {
ans = min(ans, sum);
return;
}
for (int i = 1; i <= n; i++) //枚举人员
if (!st[i]) {
st[i] = true;
dfs(step + 1, sum + a[step][i]);
st[i] = false;
}
}
int main() {
cin >> n; // n个人n个任务
// a[i][j]指的是第i项工作如果由j号员工完成所需要的时间
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
dfs(1, 0);
cout << ans << endl;
return 0;
}