5. (2006 Zhejiang Province College Entrance Examination Question Adapted) The function $f:\{1,2,3\} \rightarrow\{1,2,3\}$ satisfies $f(f(x)) \geqslant f(x)$, then the number of such functions is
A. 1
B. 4
C. 8
D. 10
5. D According to the problem, the elements in the range of the function remain the same under the action of $f$.

We classify and discuss based on the different situations of the function's range:
(1) If the range of the function $f(x)$ is a singleton set, then we have
$$
f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 1 \\
3 \rightarrow 1
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 2 \\
2 \rightarrow 2 \\
3 \rightarrow 2
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 3 \\
2 \rightarrow 3 \\
3 \rightarrow 3
\end{array}\right) ;
$$
(2) If the range of the function $f(x)$ is a set of two elements, then we have
$$
\begin{array}{l}
f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 2 \\
3 \rightarrow 1
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 2 \\
3 \rightarrow 2
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 1 \\
3 \rightarrow 3
\end{array}\right), \\
f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 3 \\
3 \rightarrow 3
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 2 \\
2 \rightarrow 2 \\
3 \rightarrow 3
\end{array}\right), f:\left(\begin{array}{l}
1 \rightarrow 3 \\
2 \rightarrow 2 \\
3 \rightarrow 3
\end{array}\right),
\end{array}
$$
(3) If the range of the function $f(x)$ is a set of three elements, then we have
$$
f:\left(\begin{array}{l}
1 \rightarrow 1 \\
2 \rightarrow 2 \\
3 \rightarrow 3
\end{array}\right) .
$$

Therefore, there are 10 functions that satisfy the condition.
Explanation: By classifying and discussing based on the number of elements in the range of the function, it is easy to generalize to the case of $n$ elements.

Generalize the function $f:\{1,2,3, \cdots, n\} \rightarrow\{1,2,3, \cdots, n\}$ that satisfies $f(f(x)) \geqslant f(x)$, then the number of such functions is _.

Analysis: Divide the set $\{1,2,3, \cdots, n\}$ into its range and its complement, where the elements in the range remain the same under the action of the function $f$, and the image of the elements in the complement can be any element in the range. For example, when $n=3$, if the range of $f$ is $\{1,2\}$ and its complement is $\{3\}$, then we have $f:\left(\begin{array}{l}1 \rightarrow 1 \\ 2 \rightarrow 2 \\ 3 \rightarrow 1\end{array}\right)$ or $\left(\begin{array}{l}1 \rightarrow 1 \\ 2 \rightarrow 2 \\ 3 \rightarrow 2\end{array}\right)$.
Thus, the number of functions with a range of one element is $C_{n}^{1}$; the number of functions with a range of two elements is $2^{n-2} C_{n}^{2}$; the number of functions with a range of $k$ elements is $k^{n-k} C_{n}^{k}$; and the number of functions with a range of $n$ elements is 1, i.e., $n^{\circ} C_{n}^{n}$.
In summary, the number of functions that satisfy the condition is
$$
C_{n}^{1}+2^{n-2} C_{n}^{k}+\cdots+k^{n-k} C_{n}^{k}+\cdots+C_{n}^{n}=\sum_{k=1}^{n} 2^{n-k} C_{n}^{k} .
$$