IT/알고리즘
[백준] 차이를 최대로
남갯
2024. 11. 14. 23:13
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