Build Array Where You Can Find The Maximum Exactly K Comparisons LeetCode solution in Python
1class Solution:2def numOfArrays(self, n: int, m: int, k: int) -> int:3@cache4def dp(a, b, c):5if a == n:6return c == k7return (b * dp(a + 1, b, c) if b >= 1 else 0) + sum(8dp(a + 1, i, c + 1) for i in range(b + 1, m + 1)9)1011return dp(0, 0, 0) % (10**9 + 7)