1
$\begingroup$

How many sequences of length $n$ with integer values from $[1, k]$ are there such that they contain all integers from $[1, k]$? You can assume that $n \ge k$. For example if $k = 3$ then $112$ is not a correct sequence, because it does not contain all numbers from $1$ to $3$.

  • 2
    Hint: try inclusion-exclusion. Start with all strings of length $n$, then subtract those that are missing one specified integer, then add those that are missing two specified integers, and so on.2017-02-20
  • 0
    Will the answer be $k^n - \binom{k}{1} (k-1)^n + \binom{k}{2} (k-2)^n - ... $?2017-02-20
  • 1
    Yes, that looks right.2017-02-20
  • 0
    Stirling numbers of the second kind.2017-02-20

1 Answers 1

1

Following lulu's hint we obtain:

$$\binom k0k^n-\binom k1 (k-1)^n+\binom k2(k-2)^n-\cdots=\sum_{r=0}^k \binom kr(-1)^r(k-r)^n$$