dp with dimensions (k+1) x (n+1) and fill it with zeros.dp[i][i] to 1 for all i from 1 to k because there is only one way to distribute i candies into i bags.i from 1 to k.i, iterate over the number of candies j from i+1 to n.dp[i][j] using the recurrence relation: dp[i][j] = (i * dp[i][j-1] + dp[i-1][j-1]) % mod where mod is 10^9 + 7.dp array, return dp[k][n] as the answer.