%I #19 Dec 16 2021 16:49:51
%S 1,0,1,1,1,2,12,7,4,4,144,62,28,12,10,2000,695,264,100,40,26,32400,
%T 9504,3126,1050,370,130,76,605052,154007,44716,13458,4256,1366,456,
%U 232,12845056,2891776,751872,204776,58784,17292,5272,1624,764
%N Number T(n,k) of endofunctions f on [n] that are self-inverse on [k] but not on [k+1]; triangle T(n,k), n>=0, 0<=k<=n, read by rows.
%C T(n,k) counts endofunctions f:{1,...,n}-> {1,...,n} with f(f(i))=i for all i in {1,...,k} and f(f(k+1))<>k+1 if k<n.
%H Alois P. Heinz, <a href="/A245692/b245692.txt">Rows n = 0..140, flattened</a>
%F T(n,k) = A245348(n,k) - A245348(n,k+1).
%e T(3,1) = 7: (1,1,1), (1,1,2), (1,1,3), (1,3,1), (1,3,3), (3,1,1), (3,3,1).
%e T(3,2) = 4: (1,2,1), (1,2,2), (2,1,1), (2,1,2).
%e T(3,3) = 4: (1,2,3), (1,3,2), (2,1,3), (3,2,1).
%e Triangle T(n,k) begins:
%e 0 : 1;
%e 1 : 0, 1;
%e 2 : 1, 1, 2;
%e 3 : 12, 7, 4, 4;
%e 4 : 144, 62, 28, 12, 10;
%e 5 : 2000, 695, 264, 100, 40, 26;
%e 6 : 32400, 9504, 3126, 1050, 370, 130, 76;
%e 7 : 605052, 154007, 44716, 13458, 4256, 1366, 456, 232;
%e ...
%p g:= proc(n) g(n):= `if`(n<2, 1, g(n-1)+(n-1)*g(n-2)) end:
%p H:= (n, k)-> add(binomial(n-k, i)*binomial(k, i)*i!*
%p g(k-i)*n^(n-k-i), i=0..min(k, n-k)):
%p T:= (n, k)-> H(n, k) -H(n, k+1):
%p seq(seq(T(n, k), k=0..n), n=0..10);
%t g[n_] := g[n] = If[n<2, 1, g[n-1] + (n-1)*g[n-2]]; H[0, 0] = 1; H[n_, k_] := Sum[Binomial[n-k, i]*Binomial[k, i]*i!*g[k-i]*n^(n-k-i), {i, 0, Min[k, n-k]}]; T[n_, k_] := H[n, k] - H[n, k+1]; Table[T[n, k], {n, 0, 10}, { k, 0, n}] // Flatten (* _Jean-François Alcover_, Feb 19 2017, translated from Maple *)
%Y Column k=0 gives A076728 for n>1.
%Y Row sums give A000312.
%Y Main diagonal gives A000085.
%Y Cf. A245348, A245693 (the same for permutations).
%K nonn,tabl
%O 0,6
%A _Alois P. Heinz_, Jul 29 2014