문제
2775 부녀회장이 될테야
풀이
층\호 | 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])
}
}