Counting all permutations(repeating) with no adjacent elements equal and m majority elements.

279 Views Asked by At

Counting all permutations(repeating) of 1 to n which have size n.
1. with no adjacent elements equal, and
2. m majority elements(A element is majority element when it appears max number of times in the permutation.)

for n = 5
{1 2 3 4 5} has 5 majority elements.
{3 2 3 2 3} has 1 majority element(3).
{3 2 3 2 1} has 2 majority elements(2, 3).

Example ->

n = 3, m = 3 => ans = 3!
{321 312 231 132 213 123}

n = 3, m = 1 => ans = 6
{121 131 212 232 313 323}

I have made a few observations,
1. If n = m then ans is always n!
2. answer for all values m > n/2 is 0.