题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 25;
int d[N][N];
int n;
int main()
{
cin >> n;
for (int i = 0; i < n; i ++)
for (int j = 0; j < n; j ++)
cin >> d[i][j];
int f[1 << n][n];
memset(f, 0x3f, sizeof f);
f[1][0] = 0;
for (int i = 0; i < (1 << n); i ++)
for (int j = 0; j < n; j ++)
if (i >> j & 1)
{
for (int k = 0; k < n; k ++)
if (i - (1 << j)>> k & 1)
f[i][j] = min(f[i][j], f[i - (1 << j)][k] + d[k][j]);
}
int res = 1e9;
for (int i = 0; i < n; i ++) res = min(res, f[(1 << n) - 1][i] + d[i][0]);
cout << res;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla