#include #include #include #include #include #include #include #include using namespace std; int N, K; vector> dot; // ユークリッド距離を計算する関数 double dist(const pair& p, const pair& q) { double x1 = p.first, y1 = p.second; double x2 = q.first, y2 = q.second; return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } // メモ化用のunordered_map map, double> memo; // メモ化された再帰関数 double calc(int pizza, int pos, int bits) { if (memo.find(make_tuple(pizza, pos, bits)) != memo.end()) { return memo[make_tuple(pizza, pos, bits)]; } double ret; if (pizza == 0) { ret = calc(K, 0, bits) + dist(dot[0], dot[pos]); } else if (bits == ((1 << (N + 1)) - 1)) { ret = dist(dot[0], dot[pos]); } else { ret = numeric_limits::max(); if (pizza != K) { ret = min(ret, calc(K, 0, bits) + dist(dot[0], dot[pos])); } for (int i = 1; i <= N; ++i) { if (!((bits >> i) & 1)) { double now = calc(pizza - 1, i, bits | (1 << i)) + dist(dot[i], dot[pos]); ret = min(ret, now); } } } memo[make_tuple(pizza, pos, bits)] = ret; return ret; } int main() { cin >> N >> K; dot.emplace_back(0.0, 0.0); for (int i = 0; i < N; ++i) { double x, y; cin >> x >> y; dot.emplace_back(x, y); } std::cout << std::fixed << std::setprecision(16); cout << calc(K, 0, 1) << endl; return 0; }