OFFSET
1,2
COMMENTS
This is a particular case (p = 1) of the more general: a(p,n) = number of permutations of the multiset {1,1,2,2,....,n,n} with exactly p times two consecutive equal terms. The sequence a(0,p) is A114938.
FORMULA
a(1,1) = 1; a(p,n+1) = a[p, n + 1] = (2*n - p + 2)*a[p-1, n] + (2*n - p + 1)*(2*n - p)*a[p, n]/2 + p*a[p, n] + (p + 1)*(2*n - p)*a[p + 1, n + (p + 2)*(p + 1)*a[p + 2, n]/2.
EXAMPLE
a(1,2) = 2, because 1221 and 2112 are the only permutations of {1,1,2,2} where exactly two consecutive terms are equal.
PROG
C-Language :
for (p = 0; p < 20; p++)
a[p][0] = 0;
for (n = 0; n < 20; n++)
a[0][n] = 0;
a[1][0] = 1;
for (n = 0; n < 18; n++)
for (p = 0; p < 18; p++)
a[p+1][n + 1] = (2*n - p + 2)*a[p][n] + (2*n - p + 1)*(2*n - p)*a[p+1][n]/2 + p*a[p+1][n] + (p + 1)*(2*n - p)*a[p + 2][n] + (p + 2)*(p + 1)*a[p + 3][n]/2 ;
for(n = 0; n < 10; n++)
{
printf("%d, %ld ", n, a[2][n]);
if (n % 5 == 0)
printf("\n\n");
}
CROSSREFS
KEYWORD
nonn
AUTHOR
Philippe Gibone, Mar 04 2012
STATUS
approved