3

I saw this question by chance online: Suppose you have a $4\times 4$ array, you wish to place 8 stones on the array such that every row and column have exactly 2 stones. How many ways can you do this?

From numerical brute force, the solution appears to be 90.

Thinking about this problem, I've come to a couple ideas:

If a configuration is valid, it is still going to be valid after a row or column exchange or taking the transpose. I don't think there is any other obvious symmetry for me to reduce the search space. With this in mind, I can fix the first row to be whatever I want, and choose the remaining 3 rows as a function of my initial choice. I was hoping I could generate a reduction formula of some sort, but I was starting to get confused keeping track of all the cases.

Another idea I had was to think about a legal configuration in terms of changing 8 values of a zero matrix into 0.5 so that I have a doubly stochastic Markov chain and think about classifying the kinds of states different Markov chains would have. This led me to the idea that a valid configuration is either "disjoint", e.g.,

$A = \begin{bmatrix} 1 & 1 & 0 & 0\\ 1 & 1 & 0 & 0\\ 0 & 0 & 1 & 1\\ 0 & 0 & 1 & 1\end{bmatrix}$

or the adjacency graph is a cycle. This seems to handle most of the cases, however, I am not sure how to handle the case when there are 1's on the main diagonal, e.g., there are loops in the graph.

I think the above graph theoretic approach is the correct line of thinking to solve the problem, but I've never taken a graph theory course and I simply don't know what tools I need to push further.

JessicaK
  • 8,007

2 Answers2

4

The "disjoint-or-cycle" classification is most of the solution here. To avoid having to think about graphs with loops - or worry about symmetry! - I would think of the $4 \times 4$ array as representing a bipartite graph between four "row" vertices $r_1, r_2, r_3, r_4$ and four "column" vertices $c_1, c_2, c_3, c_4$. Or, we can avoid worrying about graph terminology and just think about the array as a relation between rows and columns.

To get a "disjoint" case, we must:

  • Split the rows into two pairs, in $3$ ways (row $1$ can be paired with any of the other rows, and this uniquely determines the split).
  • Split the columns into two pairs, in $3$ ways.
  • Decide which row pair is going to have $1$'s with which column pair, in $2$ ways.

The result is $3 \cdot 3 \cdot 2 = 18$ disjoint cases.

To get a "cycle" case, we must choose a cyclic ordering of the rows and columns that alternates row-column-row-column-row-column-row-column. There would be $4!^2$ such orderings, but this overcounts in two ways:

  • If we have an ordering like $r_1, c_1, r_2, c_2, r_3, c_3, r_4, c_4$, this is the same as the ordering $r_4, c_4, r_1, c_1, r_2, c_2, r_3, c_3$, where we start at a different place. So we can assume we start from $r_1$ and divide by $4$.
  • If we have an ordering like $r_1, c_1, r_2, c_2, r_3, c_3, r_4, c_4$, this is the same as the ordering $r_1, c_4, r_4, c_3, r_3, c_2, r_2, c_1$, where we started at the same place but went in the opposite direction. So we can divide by $2$ again.

This makes for $\frac{4!^2}{4\cdot 2} = 72$ cycle cases, for a total of $18+72=90$, confirming the brute force solution.


The general case of this problem (for an $n\times n$ array) is given in OEIS sequence A001499. (I found this from the first few terms: we can handle anything up to $5 \times 5$ by the same method. For $6 \times 6$, we get more cases than just "cycle" and "disjoint", and a better approach seems necessary.)

Misha Lavrov
  • 159,700
  • The added structure you used by labeling the vertices in this way made the missing pieces much easier to understand. Thank you for this. – JessicaK Nov 16 '23 at 12:15
1

Pursuing your first idea—or its transpose—isn’t that bad, and can be done in a purely enumerative manner.

We can fill the first (leftmost) column in $4 \choose 2$ ways and call the two rows that now contain stones $A$ and $B$. This leaves a $4 \times 3$ (perhaps noncontiguous) subarray remaining to be populated.

We can finish filling $A$—which I’ll call saturating it—by putting its second stone in any of $3 \choose 1$ columns. At this point we’ll have a $3 \times 3$ subarray left in which to place our 5 remaining stones. And we can have reached this point, which we can call time $t_1$, in ${4 \choose 2}{3 \choose 1}=18$ ways.

If we now turn to picking the column to saturate $B$, our choice will affect the freedom that remains to us. In particular, if we saturate $B$ by choosing the same column we chose for $A$ (which we can do in only $1 \choose 1$ way), that leaves us with a $2 \times 2$ subarray in which to place the final 4 stones (which also can be done in only $4 \choose 4$ way).

But we could instead saturate $B$ with a stone in one of the $2 \choose 1$ columns still empty, and at that point we have a $2 \times 3$ subarray to populate. Let’s now switch our saturation focus from rows to columns. The column containing $A$’s second stone can be saturated by placing a stone in either of the $2 \choose 1$ remaining rows, call it $C$. Note that at this point there remains one column yet to receive any stones and only two rows that aren’t already saturated. So both of that empty column’s stones must go in the only $2 \choose 2$ rows available to it, which, in the process, must saturate $C$. And now we are left with a $1 \times 1$ subarray—the intersection of the only unsaturated row and the column containing $B$’s second stone—leaving us $1 \choose 1$ destination for our final stone.

To recap, for each of the 18 ways to reach $t_1$, we can populate the remaining $3 \times 3$ subarray in any of $${1\choose 1}{4 \choose 4} + {2 \choose 1}{2 \choose 1} {2 \choose 2}{1 \choose 1} = 5$$ ways. So, in all, there are $18\cdot 5 = 90$ ways to place 8 stones on a $4 \times 4$ grid so that each row and each column gets exactly 2 stones.