Example 3. Five people stand in a row, requiring that A does not stand at the head, B does not stand at the end, and C and D do not stand together. How many ways are there to arrange them?
Let $E=\{$ permutations of five people standing in a row $\}$,  
$A_{1}=\{$ permutations where A stands at the head $\}$,  
$A_{2}=\{$ permutations where B stands at the tail $\}$,  
$A_{3}=\{$ permutations where C and D stand together $\}$.  
Then the number of permutations required in the problem is  
$$
\begin{aligned}
& N\left(\overline{A_{1}} \cap \overline{A_{2}} \cap \overline{A_{3}}\right)=N\left(\overline{\left.A_{1} \cup A_{2} \cup A_{3}\right)}\right. \\
= & N(E)-N\left(A_{1}\right)-N\left(A_{2}\right)-N\left(A_{3}\right) \\
& +N\left(A_{1} A_{2}\right)+N\left(A_{1} A_{3}\right)+N\left(A_{2} A_{3}\right) \\
& -N\left(A_{1} A_{2} A_{3}\right) \\
= & P_{5}^{5}-P_{4}^{4}-P_{4}^{4}-P_{4} P_{2}^{2}+P_{3}^{3}+P_{3}^{2} P_{2}^{2} \\
& +P_{3}^{3} P_{2}^{2}-P_{2}^{2} P_{2}^{2} \\
= & 120-24-24-48+6+12+12-4 \\
= & 50(\text { ways }) .
\end{aligned}
$$