1
var numOfArrays = function (n, m, k) {3
// dp[i][c][j] the number of arrays of length i that cost c and their max element is j4
dp = [...Array(n + 1)].map((d) =>5
[...Array(k + 1)].map((d) => [...Array(m + 1)].map((d) => 0))7
// prefix[i][k][j] holds the prefix sum of dp[i][k][:j]8
prefix = [...Array(n + 1)].map((d) =>9
[...Array(k + 1)].map((d) => [...Array(m + 1)].map((d) => 0))29
// the previous max can be anything <j with a cost of x-1, to which we append j30
(dp[i][x][j] += prefix[i - 1][x - 1][j - 1]),31
// we can also append any number <=j to an array of length i-1 that already costs x,32
//therefore not increasing the cost33
(dp[i][x][j] += dp[i - 1][x][j] * j),35
(prefix[i][x][j] = (prefix[i][x][j - 1] + dp[i][x][j]) % mod);36
return dp[n][k].reduce((a, c) => (a + c) % mod);