원본 문제 : https://www.acmicpc.net/problem/6603
문제 참고 : https://zoonvivor.tistory.com/108
<첫번째>
import java.util.*
var n = 0
var arr: IntArray = intArrayOf()
var visited: BooleanArray = booleanArrayOf()
fun main() {
val sc: Scanner = Scanner(System.`in`)
while (true) {
n = sc.nextInt()
if (n == 0) break
arr = IntArray(n)
visited = BooleanArray(n)
for (i in 0 until n) {
arr[i] = sc.nextInt()
}
dfs(0, 0)
println()
}
}
fun dfs(start: Int, depth: Int) {
if (depth == 6)
printLotto()
for (i in start until n) {
visited[i] = true
dfs(i + 1, depth + 1)
visited[i] = false
}
}
fun printLotto() {
for (i in 0 until n) {
if (visited[i])
print("${arr[i]} ")
}
println()
}
'코딩연습' 카테고리의 다른 글
[백준] 알파벳 (1987)(Kotlin) (0) | 2020.04.07 |
---|---|
[백준] N-Queen (9663)(Kotlin) (0) | 2020.03.18 |
[백준] 퇴사 (14501)(Kotlin) (0) | 2020.02.26 |
[백준] 회의실배정 (1931)(Kotlin) (0) | 2020.02.20 |
[백준] 동전 0 (11047)(Kotlin) (0) | 2020.02.20 |
댓글