This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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;