3

Find the number of $n*n$ binary matrices that have one 1 in every row and column. This is a problem from Robert's How To Count

The answer is easy if we interpret the problem as have (exactly) one 1 in every row and column, the answer will just be $n!$

However if we interpret the problem as have (at least) one 1 in every row and column, the problem gets complicated even for n=3. How do we solve the second interpretation?

Gerry Myerson
  • 179,216

2 Answers2

1

Number of zero-one $n\times n$ matrices with no zero rows or columns is tabulated at http://oeis.org/A048291.

No closed-form formula is given there, just $$\sum_{s=0}^n{n\choose s}(-1)^s2^{(n-s)n}(1-2^{-n+s})^n$$

[What it actually says is Sum over s=0..n of binomial(n, s)*(-1)^s*2^((n-s)n)(1-2^(-n+s))^n, I hope I'm interpreting that correctly]

It is also said there that $a(n)$ is asymptotic to $2^{n^2}$. And there are some links to the literature.

Gerry Myerson
  • 179,216
1

You are probably aware of the method of inclusion-exclusion. Suppose you have a finite chain of nested sets $A\subset B\subset C\subset \cdots$ and a formula for counting each one which overcounts the subsets in predictable ways. Inclusion-exclusion lets you find $|A|$ by systematically subtracting and re-adding the overcounted elements.

Let $A_{i,j}$ be the set of binary $n\times n$ matrices with at least $i$ empty rows and at least $j$ empty columns. Naively we might guess that $|A_{i,j}|$ could be counted with $f(i,j)=\binom{n}{i}\binom{n}{j}2^{(n-i)(n-j)}$. We can draw up a diagram of these sets:

$$\begin{array}{cccc}A_{0,0}&A_{0,1}&A_{0,2}&\cdots\\A_{1,0}&A_{1,1}&A_{1,2}&\cdots\\A_{2,0}&A_{2,1}&A_{2,2}&\cdots\\\vdots&\vdots&\vdots&\ddots\end{array}$$

Each set $A_{i,j}$ contains all the sets directly south, directly east, or anywhere south-east of it: $A_{i',j'}$ where $i\le i'$ and $j\le j'$ and at least one pair is unequal. We know that $|A_{0,0}|=2^{n^2}=f(0,0)$. But how do we subtract the subsets to get the number of binary matrices with exactly zero empty rows or columns?

In fact, the number $f(i,j)$, which supposedly counts $|A_{i,j}|$, overcounts the elements of any given subset $A_{i',j'}$ by a factor of $\binom{i'}{i}\binom{j'}{j}$. Because of this, it is possible to adapt inclusion-exclusion to the two-dimensional system like so: $$\begin{array}{cccc}+f(0,0)&-f(0,1)&+f(0,2)&\cdots\\-f(1,0)&+f(1,1)&-f(1,2)&\cdots\\+f(2,0)&-f(2,1)&+f(2,2)&\cdots\\\vdots&\vdots&\vdots&\ddots\end{array}$$ This produces the formula: $$\sum_{i=0}^n\sum_{j=0}^n (-1)^{i+j}\binom{n}{i}\binom{n}{j}2^{(n-i)(n-j)}$$ which is equivalent to the one given by Jovović in the OEIS entry. The symmetry allows $(n-i)(n-j)$ to be replaced with $ij$.

Andrew Woods
  • 3,672