P(each of the digits will appear at least once) + P(one digit will not appear at all) + P(two digits will not appear at all) + P(three digits will not appear at all) +.......+P(k-1 digits will not appear at all) = 1
=> P (each of the digits will appear at least once) = 1 - [P(one digit will not appear at all) + P(two digits will not appear at all) + P(three digits will not appear at all) +.......+P(k-1 digits will not appear at all)]
Let us refer to this relationship just derived as Rel 1.
Now, P(one digit will not appear at all) = (number of ways to choose one digit from k digits)*(number of ways to fill n cells using the remaining k-1 digits)/(number of ways to fill n cells using n digits)
=> P(one digit will not appear at all) = k*(k-1)^n/k^n
Similarly, P(two digits will not appear at all) = kC2 * (k-2)^n/k^n = [k(k-1)/2]*(k-2)^n/k^n
Therefore Rel 1 becomes
P(each of the digits will appear at least once) = 1 - [k*(k-1)^n/k^n + k(k-1)*(k-2)^n/2k^n +.....
Putting in k = 3 we get
P(each of the digits will appear at least once) = 1 -[(3*2^n)/3^n + 3/3^n] = (3^n -3*2^n - 3)/3^n
=[3^n + 3 -3(2^n + 2)]/3^n
Hope this helps.