4. In how many different ways can $n$ books be arranged on a shelf so that $k$ of those books, which are numbered in advance, are in ascending or descending order.
Solution. Each choice of the positions of the numbered books is a combination of $n$ elements of class $k$ without repetition. The number of such combinations is

$$
A=\frac{n!}{k!(n-k)!}
$$

In each of the $A$ choices of positions for the numbered books, the remaining $n-k$ books are arranged arbitrarily, which gives $(n-k)!$ ways of arranging the books. The numbered books can only be ordered in two ways, i.e., in descending or ascending order.

Therefore, the desired number of ways to arrange the books is:

$$
2 \cdot A \cdot(n-k)!=2 \frac{n!}{k!} \text {. }
$$