백준 - 2775 부녀회장이 될테야 풀이
문제
2775 부녀회장이 될테야
풀이
층\호 | 1 | 2 | 3 |
---|---|---|---|
2 | 1 | 4 | 10 |
1 | 1 | 3 | 6 |
0 | 1 | 2 | 3 |
답
kotlin code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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])
}
}
This post is licensed under CC BY 4.0 by the author.