시배's Android
Algorithm | 백준 Kotlin 1965 상자넣기 본문
1965번: 상자넣기
정육면체 모양의 상자가 일렬로 늘어서 있다. 상자마다 크기가 주어져 있는데, 앞에 있는 상자의 크기가 뒤에 있는 상자의 크기보다 작으면, 앞에 있는 상자를 뒤에 있는 상자 안에 넣을 수가
www.acmicpc.net
import kotlin.math.max
private fun main() {
val N = readLine()!!.toInt()
val box = readLine()!!.split(" ").map { it.toInt() }
val dp = IntArray(N)
var count = 0
for(i in 0 until N){
dp[i] = 1
for(j in 0 until i){
if(box[j] < box[i]){
dp[i] = max(dp[j]+1, dp[i])
}
}
count = max(count, dp[i])
}
println(count)
}
'Algorithm' 카테고리의 다른 글
Algorithm | 백준 Kotlin 2553 마지막 팩토리얼 수 (0) | 2023.09.23 |
---|---|
Algorithm | 백준 Kotlin 1158 요세푸스 문제 (0) | 2023.09.23 |
Algorithm | 백준 Kotlin 15664 N과 M (10) (0) | 2023.09.16 |
Algorithm | 백준 Kotlin 2776 암기왕 (0) | 2023.09.16 |
Algorithm | Kotlin 백준 16918 봄버맨 (0) | 2023.09.11 |