Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Nov 27, 2024
1 parent b3d7d90 commit 8966926
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/kotlin/p32xx/Problem3250.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package p32xx

import util.expect

fun main() {
class Solution {
fun countOfPairs(nums: IntArray): Int {
val m = 1000000007

var dp = IntArray(51) { if (it <= nums[0]) 1 else 0 }

for (index in 1 until nums.size) {
val newDp = IntArray(51)

for (cur in 0..nums[index]) {
for (prev in 0..cur) {
if (nums[index - 1] - prev >= nums[index] - cur) {
newDp[cur] = (newDp[cur] + dp[prev]) % m
}
}
}

dp = newDp
}

return dp.fold(0) { sum, c ->
(sum + c) % m
}
}
}

expect {
Solution().countOfPairs(
intArrayOf()
)
}
}

0 comments on commit 8966926

Please sign in to comment.