一个有n个元素的排列,若一个排列中所有的元素都不在自己原来的位置上,那么这样的排列就称为原排列的一个错排
求错排的个数的问题就被称为错排问题或更列问题
递推公式
对于一个长度为n的错排,将在第n个位置的元素(设为k)与第n个元素交换,
则序列可能为一个长度为n-1的错排+n 或长度为n-2的错排+n+k
又因为位置交换有(n-1)种情况
所以$D(n)=(n-1)*(D(n-1)+D(n-2))$
通项公式
设$D(n)=n!*N(n)$,则$N(1)=0,N(2)=frac{1}{2}$
当$nge 3$时由递推公式可得$n!*N(n)=(n-1)(n-1)!*N(n-1)+(n-1)(n-2)!*N(n-2)$
两边同除$(n-1)!$得$n*N(n)=(n-1)*N(n-1)+N(n-2)$
$n*N(n)-n*N(n-1)=(-1)*N(n-1)+N(n-2)$
$N(n)-N(n-1)=-frac{N(n-1)-N(n-2)}{n}=frac{-1}{n}*(N(n-1)-N(n-2))=frac{-1}{n}*frac{-1}{n-1}*……*frac{-1}{3}*(N(2)-N(1))=frac{(-1)^n}{n!}$
同理$N(n-1)-N(n-2)=frac{(-1)^{n-1}}{(n-1)!}$
$N(n)=N(n)-N(1)=frac{(-1)^n}{n!}+frac{(-1)^{n-1}}{(n-1)!}+……+frac{(-1)^2}{2!}$
$D(n)=n!*(frac{(-1)^n}{n!}+frac{(-1)^{n-1}}{(n-1)!}+……+frac{(-1)^2}{2!})=n!*sumlimits_{i=2}^nfrac{(-1)^i}{i!}$
用容斥原理也可证明:
$ge i$个位置不是错排的方案数就为$C_n^i*(n-i)!=frac{n!}{i!}$
根据容斥原理可得$D(n)=n!*sumlimits_{i=0}^nfrac{(-1)^i}{i!}$
因为$frac{(-1)^0}{0!}+frac{(-1)^1}{1!}==0$所以$n!*sumlimits_{i=0}^nfrac{(-1)^i}{i!}=n!*sumlimits_{i=2}^nfrac{(-1)^i}{i!}$
根据通项公式又可以推出一个递推公式
$D(n)=n*D(n-1)+(-1)^n$