Count the number of selecting 5 numbers I would appreciate if somebody could help me with the following problem:
Q: Count the number of selecting 5 numbers in 
$\{1, 2, 3, ... n\} (n>5)$, excepting the choice of consecutive three numbers.
(i.e.the section does not contain consecutive three numbers.)
For example, $\{1, 2, 4, 5, 7\}$ is valid but 
$\{1, 2, 4, 5, 6\}$ is not valid.
 A: You can use an inclusion-exclusion argument. There are $\binom{n}5$ ways to select $5$ numbers from $[n]=\{1,\dots,n\}$. Picking a set of $5$ that includes $3$ adjacent numbers is like picking $3$ numbers from $[n-2]$: you can treat the block of $3$ as a single number. There are $\binom{n-2}3$ ways to do that, but the block could be any of the $3$ ‘numbers’ chosen, so there are actually $3\binom{n-2}3$ sets of $5$ that include a run of $3$ consecutive numbers. This brings the total number of acceptable choices down to
$$\binom{n}5-3\binom{n-2}3\;.\tag{1}$$
Unfortunately, the correction term in $(1)$ overcounts: a set like $\{1,2,3,4,6\}$, with a run of $4$, is subtracted twice, once with $\{1,2,3\}$ treated as a run and once with $\{2,3,4\}$, and needs to be added back in. Argue as before: treat the run of $4$ as a single ‘number’, so that you’re selecting two ‘numbers’ from $[n-3]$, either of which can be the run, for a total of $2\binom{n-3}2$ sets to be added back in to get
$$\binom{n}5-3\binom{n-2}3+2\binom{n-3}2\;.\tag{2}$$
Finally, $(2)$ counts each run of $5$ in the first term, subtracts it $3$ times in the second term, and adds it back in twice in the third term, for a net count of $0$. Since this is what we want, $(2)$ needs no further correction.
As a quick and dirty check, $(2)$ correctly gives $0$ for $n=6$ and $3$ for $n=7$, those $3$ being $\{1,2,4,5,7\},\{1,2,4,6,7\}$, and $\{1,3,4,6,7\}$.
A: Suppose $f(k,n)$ is the number of ways of selecting $k$ numbers from $n$ without three consecutive.  Then $f(k,n)$ is also the number of ways of selecting $k$ numbers from $n+1$ without three consecutive and where the last is not selected.
That then gives $f(k,n)= f(k,n-1)+f(k-1,n-2)+f(k-2,n-3)$ since you can take an existing pattern where the last is not selected, select the next 0, 1 or 2 numbers and then not select a number.  And you start with $f(0,0)=1$.  
So these are essentially trinomial coefficients and $f(n,k)$ is the coefficient of $x^{k}$ in the expansion of $(1+x+x^2)^{n-k+1}$ 
A: From n-elements of set $\{1,2,3,...,n\},n>5$ three consecutive we can choose in $n-2$ ways and from other elements we can choose 2 elements in $\binom{n-3}{2}$ ways so the number of choosing $5$ elements among them $3$ consecutive numbers is $$(n-2)\binom{n-3}{2}$$  
From all selections of $5$ elements from $n$ in $\binom{n}{5}$ ways we subtract the number of all selections that contain $3$ consecutive elements, so the desired number of subset that does not contain $3$ consecutive is 
$$\binom{n}{5}-(n-2)\binom{n-3}{2}$$   
