dp of size n+1 x 6 x max(rollMax)+1 with all elements set to 0.dp[0][i][0] to 1 for all i from 0 to 5, representing the base case of having 0 rolls.i from 1 to n.i, iterate over the last number j from 1 to 6.j, iterate over the count k from 1 to rollMax[j-1].i-1 that can end with any number except j to dp[i][j][1].k greater than 1, set dp[i][j][k] to dp[i-1][j][k-1].i by summing up all dp[i][j][k] values and take modulo 10^9+7.dp[n][j][k] values for all j and k.