dp
with dimensions (n+1) x (target+1)
and set all values to 0.dp[n][target]
to 1.diceIndex
from n-1
to 0
.
a. For each diceIndex
, loop over currSum
from 0
to target
.
b. Initialize ways
to 0.
c. Loop over the face values i
from 1
to k
.
i. If currSum + i
is less than or equal to target
, add dp[diceIndex + 1][currSum + i]
to ways
.
d. Set dp[diceIndex][currSum]
to ways
modulo 10^9 + 7
.dp[0][0]
as the final answer.