题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
import java.util.Scanner
fun main(args: Array<String>) {
val read = Scanner(System.`in`)
val res1 = read.nextLine().split(' ').map {
it.toInt()
}
val m =res1[0]
val n = res1[1]
val dp = Array(m + 1) {index1 ->
Array(n +1) {
when {
index1 ==0 ||it == 1 -> 1
else -> 0
}
}
}
for (i in 1 .. m) {
for (j in 1 .. n) {
if (j>i) {
dp[i][j] = dp[i][i]
} else {
dp[i][j] = dp[i-j][j] + dp[i][j-1]
}
}
}
println(dp[m][n])
}

