Example 5 Let $X$ be an $n$-element set, and $Y$ be an $m$-element set. Find:
(i) the number of mappings from $X$ to $Y$;
(ii) the number of surjective mappings from $X$ to $Y$.

保留了源文本的换行和格式。
(i) The image of each $x \in X$ can be any one of the $m$ $y \in Y$, so the number of mappings from $X$ to $Y$ is
$$
\overbrace{m \times m \times \cdots \times m}^{n \uparrow}=m^{n}
$$

(ii) Among the $m^{n}$ mappings, there are $(m-1)^{n}$ mappings where $y_{i}$ is not an image, $(m-2)^{n}$ mappings where $y_{i}$ and $y_{j}$ are not images, ... According to the principle of inclusion-exclusion, the number of surjective mappings is
$$
\begin{array}{l} 
m^{n}-C_{m}^{1}(m-1)^{n}+C_{m}^{2}(m-2)^{n}+\cdots+(-1)^{k} C_{m}^{k}(m-k)^{n} \\
+\cdots+(-1)^{m} C_{m}^{m-1}
\end{array}
$$