def g;gets.split.map(&:to_f)end X,Y=g n,=g L=(1..n).map{g}+[[X,Y,0]] Memo=L.map{{}} def dfs(a,left) x,y,=L[a] Memo[a][left]||=left[0]?(left.map{|i| t,u,=L[i] dfs(i,left-[i])+((x-t).abs+(y-u).abs)*(left.inject(0){|s,r|s+L[r][2]}+100.0)/120 }.min):((X-x).abs+(Y-y).abs)*(100.0)/120 end p dfs(n,[*0...n])+L.inject(0){|s,r|s+r[2]}