Problem: I would like to know the number of elements in the cartesian power $X^n$ (cartesian product of one set $X$ by itself, $n$ times) with a majority constraint: how many elements in $X^n$ have a (relative) majority of one element of the set (say $x\in X$)?
On top of that, I'd like to fix one element in the cartesian power to a certain value (say the second), and count the number of possibilities with this fixed value.
Simple example: with $X=\{A, B, C\}$ and $n=4$. The question is: how many four-letter words with an $A$ in the second position have a (relative) majority of $A$'s? And how many have a (relative) majority of $B$'s?
Solution for the simple example: We can iterate on the total number $k$ of the element we want as a (relative) majority (say $A$).
- With $k=4$ elements being $A$, there is 1 option ($A$ is the majority, and $A$ is in the second position)
$AAAA$
- With $k=3$ elements being $A$, there are three possibilities for locating $A$'s. The second element is $A$ by constraint. The two extra $A$'s can be in position $(1,3), (1,4)$ or $(3,4)$. And there is one free position, where it can be everything but $A$: 2 possibilities. In total: $3\times 2=6$ possibilities.
$AAAB, AAAC, AABA, AACA, BAAA, CAAA$
- With $k=2$ elements being $A$'s, there is an extra-challenge: the two remaining positions should not be the same, otherwise $A$'s are not a majority anymore. About locating the $A$'s, one is fixed in the second position and the other $A$ can be in position $(1)$, $(3)$ or $(4)$: 3 possibilities. In the two remaining positions, there are 2 possibilities for the first one ($B$ or $C$ but not $A$) and 1 possibility for the second one (not $A$ and not the same than the first one). Total: 6 possibilities.
$AABC, AACB, BAAC, CAAB, BACA, CABA$
- With $k=1$ element being $A$, there are zero possibilities for $A$ to be a majority (three remaining possibilities, with only two letters, $B$ and $C$, so necessarily a majority of $B$ or $C$).
So with $n=4$ and 3 elements in the original set, there are 13 possibilities.
General solution? Is there a closed form formula to compute this number?
Same problem, expressed in a network formulation: In a network with 3 rows ($\{A, B, C\}$) and $n=4$ columns, assuming paths from left to right (e.g., using node $A_1$, then $B_2$, then $A_3$ and finally $C_3$), the question becomes: how many paths are going through node $A_2$ and have a (relative) majority of $A$ nodes?
Same problem, expressed in a voting context: Calculate winning outcomes of plurality voting
Let $|X|=m$ (the number of candidates) and $n$ be the number of voters. For the first question, by the basic theory of exponential generating functions, the number of ways for candidate $A$ to get a plurality of votes is the coefficient of $\frac{x^n}{n!}$ in the sum $$\sum_{k\ge0} \frac{x^k}{k!}\left(1+x+\frac{x^2}{2!}+\cdots+\frac{x^{k-1}}{(k-1)!}\right)^{m-1}.$$ To see this, sum over all possible numbers $k$ of votes that $A$ gets; the other $m-1$ candidates can get up to $k-1$ votes each. (Some terms in this sum are zero, but that's OK.)
For the second question, if you fix one of the votes, there are two possibilities, depending on whether you're fixing a vote for $A$ or for another candidate. In the former case, the answer will be $$\left[\frac{x^{n-1}}{(n-1)!}\right] \sum_{k\ge0} \frac{x^{k-1}}{(k-1)!}\left(1+x+\frac{x^2}{2!}+\cdots+\frac{x^{k-1}}{(k-1)!}\right)^{m-1} $$
since we now have to place $k-1$ votes for $A$. (This gives the same $13$ as in your example.) Similarly, if you're fixing a vote for one of the other candidates, the expression becomes $$\left[\frac{x^{n-1}}{(n-1)!}\right] \sum_{k\ge0} \frac{x^{k}}{k!}\left(1+x+\frac{x^2}{2!}+\cdots+\frac{x^{k-1}}{(k-1)!}\right)^{m-2}\left(1+x+\frac{x^2}{2!}+\cdots+\frac{x^{k-2}}{(k-2)!}\right). $$