시배's Android
Algorithm | 백준 Kotlin 15664 N과 M (10) 본문
private fun main() {
val (n, m) = readLine()!!.split(" ").map { it.toInt() }
val arr = readLine()!!.split(" ").map { it.toInt() }.sorted()
fun go(i: Int, s: List<Int>) {
if (s.size == m) {
println(s.joinToString(" "))
return
}
for (j in i until n) {
if (j == i || arr[j] != arr[j - 1]) {
go(j + 1, s + arr[j])
}
}
}
go(0, listOf())
}
'Algorithm' 카테고리의 다른 글
Algorithm | 백준 Kotlin 1158 요세푸스 문제 (0) | 2023.09.23 |
---|---|
Algorithm | 백준 Kotlin 1965 상자넣기 (0) | 2023.09.16 |
Algorithm | 백준 Kotlin 2776 암기왕 (0) | 2023.09.16 |
Algorithm | Kotlin 백준 16918 봄버맨 (0) | 2023.09.11 |
Algorithm | Kotlin 백준 1059 좋은 구간 (0) | 2023.09.11 |