Rujia Great White Book P61 page
#include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include < iostream>using namespace std; #define INF 0x3f3f3f3f#define N 21struct point{double x, y, Z;} P[n];d ouble x[n], y[n];d ouble d[1 << N];d ouble Dist (Point A, point B) {return sqrt ((a.x-b.x) * (a.x-b.x) + (a . Y-b.y) * (A.Y-B.Y) + (a.z-b.z) * (A.Z-B.Z));} int main () {freopen ("BB.txt", "R", stdin); int n; scanf ("%d", &n); for (int i = 0; i < n; i++) {scanf ("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z); } for (int i = 0; i < (1 << n); i++) d[i] = INF; D[0] = 0; for (int s = 3; s < (1 << n); s++) {int I, J; for (i = 0; i < n; i++) if (S & (1 << i)) break; for (j = i + 1; j < N; j + +) if (S & (1 << j)) D[s] = min (d[s], D[s ^ (1<<i) ^ (1<<J)] + Dist (P[i], p[j])); } printf ("%.3lf\n", d[(1<<n)-1]);return 0;} /*201 2 31 1 15 6 24 7 82 3 11 4 72 5 83 6 91 2 52 3 64 5 27 8 54 5 1-1 2 3-1-9-70 0 0100 0 09 5 17 5 35 5 5*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Collection DP point set matching problem