【Example 9】There are $r$ balls numbered from 1 to $r$ and $n$ boxes numbered from 1 to $n$, where $r \geqslant n$. Now the balls are placed into the boxes, with no limit on the capacity of each box. Find the number of ways $f(r, n)$ such that no box is empty. If the $n$ boxes are unnumbered and indistinguishable, still find the number of ways $s(r, n)$ such that no box is empty.
Let $B$ denote the set of all ways to place balls such that at least one box is empty. Introduce the sets $B_{1}, B_{2}, \cdots, B_{n}$, which respectively represent the subsets of ways to place balls where the $1, 2, \cdots, n$-th box is empty. Then we have $B=B_{1} \cup B_{2} \cup \cdots \cup B_{n}$.

In the ways within $B_{i}$, the $i$-th box is not used, and the other boxes can be filled arbitrarily, so $\left|B_{i}\right|=(n-1)^{r}, 1 \leqslant i \leqslant n$. In $B_{i} \cap B_{j}$, the $i$-th and $j$-th boxes are not used, and the other boxes can be filled arbitrarily, so $\left|B_{i} \cap B_{j}\right|=(n-2)^{r}, 1 \leqslant i<j \leqslant n$. Similarly, we can deduce that the intersection of any $k$ of $B_{1}, B_{2}, \cdots, B_{n}$ contains $(n-k)^{r}$ ways. Thus, we have
$$
\begin{array}{l}
S_{1}=C_{n}^{1} \cdot(n-1)^{r}, S_{2}=C_{n}^{2} \cdot(n-2)^{r}, \cdots, \\
S_{k}=C_{n}^{k} \cdot(n-k)^{r}, \cdots
\end{array}
$$

Therefore, by the principle of inclusion-exclusion, we have
$$
\begin{aligned}
|B|= & C_{n}^{1} \cdot(n-1)^{r}-C_{n}^{2} \cdot(n-2)^{r}+\cdots+(-1)^{k+1} C_{n}^{k} \\
& \cdot(n-k)^{r}+\cdots+(-1)^{n} C_{n}^{n-1}
\end{aligned}
$$

If we place $r$ balls into $n$ boxes arbitrarily, there are $n^{r}$ ways to do so. Therefore, the number of ways to place the balls such that no box is empty is
$$
\begin{aligned}
f(r, n)= & n^{r}-|B| \\
= & C_{n}^{n} \cdot n^{r}-C_{n}^{1} \cdot(n-1)^{r}+C_{n}^{2} \cdot(n-2)^{r} \\
& +\cdots+(-1)^{n-1} C_{n}^{n-1}
\end{aligned}
$$

In the case where the boxes are not labeled, we have $S(r, n)=\frac{1}{n!} f(r, n)$, so
$$
\begin{aligned}
S(r, n)= & \frac{1}{n!}\left[C_{n}^{0} \cdot n^{r}-C_{n}^{1} \cdot(n-1)^{r}+C_{n}^{2} \cdot(n-2)^{r}\right. \\
& \left.+\cdots+(-1)^{n-1} C_{n}^{n-1}\right]
\end{aligned}
$$