SMALL
https://www.acmicpc.net/problem/10819
fun main() = with(Scanner(System.`in`)) {
val count = nextInt()
val visited = Array<Boolean>(count) { false }
val array = Array(count) { 0 }
for (i in array.indices) {
array[i] = nextInt()
}
var result = 0
fun dfs(depth: Int, total: Int , current : Int) {
if (depth == count - 1) {
result = max(result, total)
return
}
for (i in 0 until count) {
if (visited[i]) continue
visited[i] = true
dfs(depth = depth + 1, total = total + abs(current - array[i]) , current = array[i])
visited[i] = false
}
}
for(i in 0 until count){
visited[i] = true
dfs(depth = 0, total = 0 , current = array[i])
visited[i] = false
}
println(result)
}
LIST
'IT > 알고리즘' 카테고리의 다른 글
[백준] 1,2,3 더하기 (0) | 2024.11.14 |
---|---|
[백준] 퇴사 (0) | 2024.11.12 |
[백준] 좋은수열 (0) | 2024.11.11 |
[백준] 단어수학 (2) | 2024.11.11 |
[프로그래머스] 3xn 타일링 (0) | 2024.11.11 |