diff --git a/code_study/Baekjoon/swift/15686.swift b/code_study/Baekjoon/swift/15686.swift new file mode 100644 index 0000000..a94974a --- /dev/null +++ b/code_study/Baekjoon/swift/15686.swift @@ -0,0 +1,82 @@ +func combination(_ n: Int, _ r: Int) -> [[Int]] { + var resultComb: [[Int]] = [] + var currentComb: [Int] = [] + + func backtracking(_ start: Int) { + if currentComb.count == r { + resultComb.append(currentComb) + return + } + + for i in start...n { + currentComb.append(i) + backtracking(i + 1) + currentComb.removeLast() + } + } + + backtracking(0) + + return resultComb +} + +if let input = readLine(), + let NM = input.split(separator: " ").compactMap({Int($0)}) as? [Int], + let N = NM.first, let M = NM.last +{ + var house: [[Int]] = [] + var chicken: [[Int]] = [] + + for i in 0.. tempDistMin { + minDistance = tempDistMin + } + } + distanceMinSum = minDistance + } + print(distanceMinSum) +}