/* -*- coding: utf-8 -*- * * 2955.cc: No.2955 Pizza Delivery Plan - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 14; const int NBITS = 1 << MAX_N; const double DINF = 1e60; /* typedef */ /* global variables */ int xs[MAX_N], ys[MAX_N]; double es[MAX_N][MAX_N], oes[MAX_N]; int bnums[NBITS]; double dp[NBITS][MAX_N][MAX_N + 1]; /* subroutines */ inline double dist(double dx, double dy) { return sqrt(dx * dx + dy * dy); } inline void setmin(double &a, double b) { if (a > b) a = b; } /* main */ int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d%d", xs + i, ys + i); for (int i = 0; i < n; i++) { oes[i] = dist(xs[i], ys[i]); es[i][i] = 0.0; for (int j = i + 1; j < n; j++) es[i][j] = es[j][i] = dist(xs[j] - xs[i], ys[j] - ys[i]); } int nbits = 1 << n; for (int bits = 1, msb = 1; bits < nbits; bits++) { if ((msb << 1) <= bits) msb <<= 1; bnums[bits] = bnums[bits ^ msb] + 1; } for (int bits = 0; bits < nbits; bits++) for (int i = 0; i < n; i++) fill(dp[bits][i], dp[bits][i] + k + 1, DINF); for (int i = 0; i < n; i++) dp[1 << i][i][1] = oes[i]; for (int bits = 0; bits < nbits; bits++) { for (int i = 0; i < n; i++) for (int j = 1; j <= k; j++) if (dp[bits][i][j] < DINF) { for (int i1 = 0, bi = 1; i1 < n; i1++, bi <<= 1) if (! (bits & bi)) { setmin(dp[bits | bi][i1][1], dp[bits][i][j] + oes[i] + oes[i1]); if (j < k) setmin(dp[bits | bi][i1][j + 1], dp[bits][i][j] + es[i][i1]); } } } double mind = DINF; for (int i = 0; i < n; i++) for (int j = 1; j <= k; j++) setmin(mind, dp[nbits - 1][i][j] + oes[i]); printf("%.11lf\n", mind); return 0; }