'commit'
This commit is contained in:
34
TangDou/XiTi/1316.cpp
Normal file
34
TangDou/XiTi/1316.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user