5. There are $p+q$ parts, of which $p$ are good and $q$ are defective. Now, they are checked one by one at random. The probability that all defective parts are found exactly when the $r$-th part is checked, where $q<p<r<p+q$, is $\qquad$ .
5. $\frac{\mathrm{C}_{q}^{1} \mathrm{~A}_{r-1}^{q-1} \mathrm{~A}_{p}^{-q}+\mathrm{C}_{p}^{1} \mathrm{~A}_{r-1}^{p-1} \mathrm{~A}_{q}^{r-p}}{\mathrm{~A}_{p+q}^{r}}$.

The original problem is equivalent to: From the numbers $1,2, \cdots, p$ and $-1,-2, \cdots,-q$, randomly select $r$ numbers and arrange them in a row. Find the probability that the resulting permutation satisfies the following conditions: either the permutation contains $q$ negative numbers, and the last number is negative (in this case, it contains at most $p-1$ positive numbers); or the permutation contains $p$ positive numbers, and the last number is positive (in this case, it contains at most $q-1$ negative numbers).

If the $r$-th position is a negative number, then there are $\mathrm{C}_{q}^{1}$ ways to arrange this position, the remaining $q-1$ negative numbers are all arranged in the first $r-1$ positions, with $\mathrm{A}_{r-1}^{q-1}$ ways, and the remaining $r-q$ positions are arranged with $r-q$ numbers chosen from $p$ positive numbers, with $\mathrm{A}_{p}^{r-q}$ ways; if the $r$-th position is a positive number, then there are $\mathrm{C}_{p}^{1}$ ways to arrange this position, the remaining $p-1$ positive numbers are all arranged in the first $r-1$ positions, with $\mathrm{A}_{r-1}^{p-1}$ ways, and the remaining $r-p$ positions are arranged with $r-p$ numbers chosen from $q$ negative numbers, with $\mathrm{A}_{q}^{r-p}$ ways.

Since there are $\mathrm{A}_{p+q}^{r}$ permutations of selecting $r$ numbers from $p+q$ numbers, the required probability is
$$
\frac{\mathrm{C}_{q}^{1} \mathrm{~A}_{r-1}^{q-1} \mathrm{~A}_{p}^{r-q}+\mathrm{C}_{p}^{1} \mathrm{~A}_{r-1}^{p-1} \mathrm{~A}_{q}^{r-p}}{\mathrm{~A}_{p+q}^{r}} .
$$