-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1433.cpp
54 lines (54 loc) · 1.09 KB
/
P1433.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
int n;
struct cheese
{
int x, y;
};
struct cheese c[16];
bool way[16];
double path[16][16];
double length_mini = 1 << 29;
void dfs(int last_point, int i, double path_sum)
{
if (path_sum > length_mini)
{
return;
}
if (i == n)
{
length_mini = min(length_mini, path_sum);
return;
}
for (int k = 1; k <= n; k++)
{
if (!way[k])
{
way[k] = true;
dfs(k, i + 1, path_sum + path[last_point][k]);
way[k] = false;
}
}
}
int main()
{
cin >> n;
c[0].x = 0, c[0].y = 0;
for (int i = 1; i <= n; i++)
{
cin >> c[i].x >> c[i].y;
}
for (int i = 0; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
int x1 = c[i].x, y1 = c[i].y;
int x2 = c[j].x, y2 = c[j].y;
path[i][j] = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
path[j][i] = path[i][j];
}
}
dfs(0, 0, 0);
cout << fixed << setprecision(2) << length_mini;
return 0;
}