## https://yukicoder.me/problems/no/2955 import math def main(): N, K = map(int, input().split()) xy = [] for _ in range(N): x, y = map(int, input().split()) xy.append((x, y)) # 原点からの距離を計算 dists_from_origins = [] for x, y in xy: d = math.sqrt(x ** 2 + y ** 2) dists_from_origins.append(d) # 点i -> 点jのの移動距離の計算 matrix = [[-1] * N for _ in range(N)] for i in range(N): for j in range(N): x1, y1 = xy[i] x2, y2 = xy[j] d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 ) matrix[i][j] = d # popcountがK以下のbit(一度に宅配できる住宅の組み合わせ)ごとに最短でどれくらい帰ってくるかの計算を実施 base_bits = [[] for _ in range(K + 1)] for bit in range(2 ** N): popcount = 0 for i in range(N): if bit & (1 << i) > 0: popcount += 1 if popcount <= K: base_bits[popcount].append(bit) dp = {} for i in range(N): if (1 << i) not in dp: dp[1 << i] = {} dp[1 << i][i] = dists_from_origins[i] for k in range(1, K): b_bits = base_bits[k] for bit in b_bits: for j in range(N): if bit & (1 << j) > 0: continue new_bit = bit | (1 << j) for last, cost in dp[bit].items(): new_cost = cost + matrix[last][j] if new_bit not in dp: dp[new_bit] = {} if j not in dp[new_bit]: dp[new_bit][j] = float("inf") dp[new_bit][j] = min(dp[new_bit][j], new_cost) new_bit = {} for bit, bit_map in dp.items(): base_cost = float("inf") for key, cost in bit_map.items(): c = dists_from_origins[key] + cost base_cost = min(base_cost, c) new_bit[bit] = base_cost # --------- answer_dp = [float("inf")] * ( 2 ** N) answer_dp[0] = 0.0 for bit in range(1, 2 ** N): b = bit while b > 0: b_ = bit - b if b in new_bit: ans = new_bit[b] + answer_dp[b_] answer_dp[bit] = min(answer_dp[bit], ans) b = (b - 1) & bit print(answer_dp[2 ** N - 1]) if __name__ == "__main__": main()