• Home
  • About
    • back
    • Moon photo

      Moon

      개발자는 자고 싶다.

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • back
    • All Posts
    • All Tags
  • Projects

백준 - 2775 부녀회장이 될테야 풀이

05 Jun 2022

Reading time ~1 minute

문제

2775 부녀회장이 될테야

screencapture

풀이

층\호 1 2 3
2 1 4 10
1 1 3 6
0 1 2 3

답

kotlin code

fun main() {
    q2775()
}

fun q2775() {
    val inputs = Array(readln().toInt()){Pair(readln().toInt(), readln().toInt())}

    val maxHeight = inputs.maxOf { it.first }
    val maxWidth = inputs.maxOf { it.second }
    val building = Array(maxHeight+1) { IntArray(maxWidth) }
    for (w in 0 until maxWidth) {
        building[0][w] = w + 1
    }
    for(h in 1..maxHeight) {
        for(w in 0 until maxWidth) {
            building[h][w] = building[h-1].copyOfRange(0, w+1).sum()
        }
    }

    for(input in inputs) {
        println(building[input.first][input.second-1])
    }
}


baekjoonkotlin코틀린백준브론즈수학구현풀이 Share Tweet +1