Example 2 Place $n$ distinct balls into $r(n \geqslant r)$ boxes, with no limit on the number of balls in each box. Find the number of ways to place the balls such that no box is empty in the following scenarios:
(1) The $r$ boxes are distinct (distinguishable);
(2) The $r$ boxes are identical (indistinguishable).
(1) Since the $r$ boxes are distinct, we can number them as $1,2, \cdots, r$, and let $S$ denote the set of all ways to place $n$ balls into these $r$ boxes. Let $M$ denote the set of ways with at least one empty box, and $\bar{M}$ denote the set of ways with no empty boxes. Let $M_{i}$ be the set of ways where the $i$-th box is empty, then
$$
M=M_{1} \cup M_{2} \cup \cdots \cup M_{r}, \bar{M}=\bar{M}_{1} \cap \bar{M}_{2} \cap \cdots \cap \bar{M}_{r},
$$

where $\bar{M}_{i}$ denotes the set of ways where the $i$-th box is not empty.
First, calculate $|S|$. Since each of the $n$ distinct balls can be placed into any of the $r$ distinct boxes, and there is no limit on the number of balls in each box, we have $|S|=r^{n}$.

Next, calculate $\left|M_{i}\right|$. Since the $i$-th box is empty, each ball must be placed in one of the other $r-1$ boxes, so $\left|M_{i}\right|=(r-1)^{n}(1 \leqslant i \leqslant r)$. Similarly, $\left|M_{i} \cap M_{j}\right|=(r-2)^{n}(1 \leqslant i<j \leqslant r), \cdots$, $\left|M_{i_{1}} \cap M_{i_{2}} \cap \cdots \cap M_{i_{k}}\right|=(r-k)^{n}\left(1 \leqslant i_{1} \leqslant i_{2}<\cdots<i_{k} \leqslant r\right)$. Therefore, by the principle of inclusion-exclusion, we get
$$
\begin{aligned}
f(n, r) & =|\vec{M}|=\left|\bar{M}_{1} \cap \bar{M}_{2} \cap \cdots \cap \bar{M}_{r}\right| \\
& =r^{n}-C_{r}^{1}(r-1)!+C_{r}^{2}(r-2)!-C_{r}^{3}(r-3)!+\cdots+(-1)^{r-1} C_{r}^{r-1} \cdot 1!,
\end{aligned}
$$

which is the number of ways to place $n$ balls into $r$ distinguishable boxes with no empty boxes.
(2) Since the $r$ boxes are indistinguishable, if the number of ways with no empty boxes is denoted by $S(n, r)$, then $f(n, r)=r!S(n, r)$, so $S(n, r)=\frac{1}{r!} f(n, r)=\frac{1}{r!}\left[r^{n}-C_{r}^{1}(r-1)^{n}+C_{r}^{2}(r-2)^{n}-\cdots+(-1)^{r-1} C_{r}^{r-1} \cdot 1^{n}\right]$.