OFFSET
4,2
LINKS
Hugo M. Spinelli, Program code related to this sequence
FORMULA
a(n) = ( (n^4 - 10*n^3 + 37*n^2 - 56*n + 25) * A000166(n-4) + (-1)^n * (-n^3 + 8*n^2 - 22*n + 19) ) / 4. - Max Alekseyev, Sep 22 2009
EXAMPLE
a(4)=1 because "aabb" has only one derangement: "bbaa";
a(5)=4 because "aabbc" has four derangements: "bbaca", "bbcaa", "bcaab" and "cbaab".
MATHEMATICA
A000166[n_] := Floor[n!/E + 1/2]; a[4] = 1; a[n_] := ((n^4 - 10*n^3 + 37*n^2 - 56*n + 25)*A000166[n-4] + (-1)^n*(-n^3 + 8*n^2 - 22*n + 19))/4; Table[ a[n], {n, 4, 21}] (* Jean-François Alcover, Jan 30 2012, after Max Alekseyev *)
CROSSREFS
KEYWORD
nonn,nice
AUTHOR
Hugo M. Spinelli (woodcroft(AT)poli.ufrj.br), Jul 02 2008, Jul 25 2008
EXTENSIONS
Extended by Max Alekseyev, Sep 22 2009
STATUS
approved