Files
python/TangDou/Dfs/DFS14.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
860 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}