#include #include #include #include #include #include #include int main() { std::cin.tie(nullptr)->sync_with_stdio(false); std::mt19937 mt{std::random_device{}()}; // while (true) { int N, K; // N = mt() % 5 + 1; // K = mt() % N + 1; std::cin >> N >> K; std::vector X(N), Y(N); // std::cerr << N << ' ' << K << std::endl; // for (int i{} ; i < N ; i++) { // X[i] = mt() % (int)2e9 - 1e9; // Y[i] = mt() % (int)2e9 - 1e9; // std::cerr << X[i] << ' ' << Y[i] << std::endl; // } for (int i{} ; i < N ; i++) std::cin >> X[i] >> Y[i]; const long double INF{(long double)1e18}; std::vector dp(N, std::vector(1 << N, INF)); for (int i{} ; i < N ; i++) { dp[i][1 << i] = sqrtl((long double)X[i] * X[i] + (long double)Y[i] * Y[i]); } for (int bit{} ; bit < (1 << N) ; bit++) { for (int s{} ; s < N ; s++) if (bit & (1 << s)) { for (int t{} ; t < N ; t++) if (!(bit & (1 << t))) { if (dp[s][bit] > 1e15) continue; int dx{X[s] - X[t]}, dy{Y[s] - Y[t]}; dp[t][bit | (1 << t)] = std::min(dp[t][bit | (1 << t)], dp[s][bit] + sqrtl((long double)dx * dx + (long double)dy * dy)); // std::cout << s << ' ' << bit << " -> " << t << ' ' << dp[s][bit] << std::endl; } } } std::vector cost(1 << N, INF); cost[0] = 0; for (int bit{} ; bit < (1 << N) ; bit++) for (int i{} ; i < N ; i++) if (bit & (1 << i)) { if (dp[i][bit] > 1e15) continue; cost[bit] = std::min(cost[bit], dp[i][bit] + sqrtl((long double)X[i] * X[i] + (long double)Y[i] * Y[i])); } for (int bit{} ; bit < (1 << N) ; bit++) assert(cost[bit] < 1e15); std::vector ep(1 << N, INF); ep[0] = 0; int all{(1 << N) - 1}; for (int bit{} ; bit < (1 << N) ; bit++) { // assert(ep[bit] < 1e15); int can{all ^ bit}; for (int mask{can} ; mask ; mask = (mask - 1) & can) { if ((int)std::popcount((unsigned)mask) <= K) { assert((bit & mask) == 0); ep[bit | mask] = std::min(ep[bit | mask], ep[bit] + cost[mask]); } } } std::cout << std::fixed << std::setprecision(8) << ep[all] << '\n'; // } }