-
[Swift] ๋ฐฑ์ค 1697 ์จ๋ฐ๊ผญ์ง (Graph Traversal)๐ป Algorithm/Swift 2023. 2. 12. 17:18
๐ ํ์ด
๐ฌ Code
import Foundation let input = readLine()!.split(separator: " ").map { Int(String($0))! } let n = input[0] let m = input[1] var isUsed = [Bool].init(repeating: false, count: n+1) backTracking(0, []) func backTracking(_ cnt: Int, _ arr: [String]) { if cnt == m { print(arr.joined(separator: " ")) return } for i in 1...n where !isUsed[i] { isUsed[i] = true backTracking(cnt+1, arr+[String(i)]) isUsed[i] = false } }
'๐ป Algorithm > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค 1926 ๊ทธ๋ฆผ (Graph Traversal) (0) 2023.02.12 [Swift] ๋ฐฑ์ค 15649 N๊ณผ M (1) (Back Tracking) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 10026 ์ ๋ก์์ฝ (Graph Traversal) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 2178 ๋ฏธ๋ก ํ์ (Graph Traversal) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 2667 ๋จ์ง๋ฒํธ๋ถ์ด๊ธฐ (Graph Traversal) (0) 2023.01.31