Example 1 (Derangement) If a permutation $\left\{i_{1}, i_{2}, \cdots, i_{n}\right\}$ of $\{1,2, \cdots, n\}$ satisfies $i_{1} \neq 1, i_{2} \neq 2, \cdots$, $i_{n} \neq n$, then $\left\{i_{1}, i_{2}, \cdots, i_{n}\right\}$ is called a derangement of $\{1,2, \cdots, n\}$. Try to find the number of all derangements $D_{n}$ of $\{1,2, \cdots, n\}$.
Let the set of all permutations of $\{1,2, \cdots, n\}$ be denoted as $S$, then obviously $|S|=n!$. Let $A_{j}=\left\{\left(i_{1}, i_{2}, \cdots\right.\right.$, $\left.i_{n}\right) \mid\left(i_{1}, i_{2}, \cdots, i_{n}\right) \in S$ and $\left.i_{j}=j\right\}(j=1,2, \cdots, n)$, thus $D_{n}=\left|\bar{A}_{1} \cap \bar{A}_{2} \cap \cdots \cap \bar{A}_{n}\right|$, and it is easy to see that
$$
\begin{array}{l}
\left|A_{j}\right|=(n-1)!(1 \leqslant j \leqslant n),\left|A_{i} \cap A_{j}\right|=(n-2)!(1 \leqslant i<j \leqslant n), \cdots, \\
\left|A_{i_{1}} \cap A_{i_{2}} \cap \cdots \cap A_{i_{r}}\right|=(n-r)!\left(1 \leqslant i_{1}<i_{2}<\cdots<i_{r} \leqslant n\right), \cdots, \\
\left|A_{1} \cap A_{2} \cap \cdots \cap A_{n}\right|=0!=1 .
\end{array}
$$

Therefore, by the principle of inclusion-exclusion, we get
$$
\begin{aligned}
D_{n} & =|S|-\sum_{i=1}^{n}\left|A_{i}\right|+\sum_{1 \leqslant i<j \leqslant n}\left|A_{i} \cap A_{j}\right|-\cdots+(-1)^{n}\left|A_{1} \cap A_{2} \cap \cdots \cap A_{n}\right| \\
& =n!-C_{n}^{1}(n-1)!+C_{n}^{2}(n-2)!-C_{n}^{3}(n-3)!+\cdots+(-1)^{n} C_{n}^{n} \cdot 0! \\
& =n!\left(1-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\cdots+\frac{(-1)^{n}}{n!}\right) .
\end{aligned}
$$

Let $S_{j}$ denote the set of all derangements where the first position is $j(2 \leqslant j \leqslant n)$. Clearly, $\left|S_{2}\right|=\left|S_{3}\right|=\cdots=\left|S_{n}\right|$ (denote this number as $d_{n}$), thus
$$
\left|D_{n}\right|=\left|S_{2}\right|+\left|S_{3}\right|+\cdots+\left|S_{n}\right|=(n-1) d_{n} \text {. }
$$

Next, divide the permutations in $S_{2}$ into two categories: $S^{\prime}{ }_{2}$ represents the set of derangements in $S_{2}$ where the second position is 1, and $S^{\prime \prime}{ }_{2}$ represents the set of derangements in $S_{2}$ where the second position is not 1. Thus, $S^{\prime}{ }_{2}$ has the form $2,1, i_{3}, i_{4}, \cdots$, $i_{n}$, where $i_{3}, i_{4}, \cdots, i_{n}$ are a derangement of $3,4, \cdots, n$, hence $\left|S^{\prime}{ }_{2}\right|=D_{n-2}$. And $S^{\prime \prime}{ }_{2}$ has the form $2, i_{2}, i_{3} \cdots i_{n}$, where $i_{2} \neq 1, i_{j} \neq j(j=3,4, \cdots, n)$, i.e., $i_{2}, i_{3}, \cdots, i_{n}$ are a derangement of 1, $3,4, \cdots, n$, hence $\left|S^{\prime \prime}{ }_{2}\right|=D_{n-1}$,
so $d_{n}=\left|S_{2}\right|=\left|S^{\prime}{ }_{2}\right|+\left|S^{\prime \prime}{ }_{2}\right|=D_{n-2}+D_{n-1}$,
thus $D_{n}=(n-1) d_{n}=(n-1)\left(D_{n-1}+D_{n-2}\right)(n \geqslant 3)$, and it is clear that $D_{1}=0, D_{2}=1$, so
$$
\begin{aligned}
D_{n}-n D_{n-1} & =-\left[D_{n-1}-(n-1) D_{n-2}\right] \\
& =(-1)^{2}\left[D_{n-2}-(n-2) D_{n-3}\right]=\cdots \\
& =(-1)^{n-2}\left(D_{2}-D_{1}\right)=(-1)^{n} . \\
\frac{D_{n}}{n!}-\frac{D_{n-1}}{(n-1)!} & =\frac{(-1)^{n}}{n!},
\end{aligned}
$$

Therefore, $\frac{D_{n}}{n!}=\frac{D_{1}}{1!}+\sum_{k=2}^{n}\left(\frac{D_{k}}{k!}-\frac{D_{k-1}}{(k-1)!}\right)=0+\sum_{k=2}^{n}\left(\frac{(-1)^{k}}{k!}\right)=\sum_{k=0}^{n} \frac{(-1)^{k}}{k!}$,
so $D_{n}=n!\left(1-\frac{1}{1!}+\frac{1}{2!}+\cdots+\frac{(-1)^{n}}{n!}\right)$.