Number of derangements on $[n]$ when there exists an extra limitation

64 Views Asked by At

Let $[n]$ be a set with $n$ elements,How many permutations $\sigma$ of this set exist such that: $$\forall i\in [n]:\sigma (i) \ne i \;\;\;\;\text{and}\;\;\;\; \sigma (n) \ne n-1$$

I tried several times ,for example one of the strategies I used was:

Since $\sigma (n) \ne n$ and $\sigma (n) \ne n-1$ , so $\sigma (n) = i$ where $1\le i\le n-2$, so there are $n-2$ choices,now we are left with the $n-1$ remaining elements for which $\sigma$ does not have any fixed point, so the answer is $!\left(n-1\right)\left(n-2\right)$.

Then I figured out that the formula is wrong,since for the $n-1$ remaining elements ,there are two of them for which their fixed point is the same,namely $n-1$ and $n$,because $\sigma (n-1) \ne n-1$ by derangement and $\sigma (n) \ne n-1$ by the assumption,and we use derangement formula when there does not exist two distinct elements in $[n]$ with the same fixed point.

So what is the answer?