Chess Picking Problem
Rephrase the chess picking problem in a more formal way.
Problem Statement
Let be the set of 0-1 matrices such that
- All matrices have the same number of 's
- Any submatrix has at least one
- The number of 1's, , is the minimal possible value
Calculate and .
Solution
Minimal Number of 1's
Let act on by reordering the rows and columns. Clearly, this group action is well-defined. Now consider , the number of different orbits. We can use one to make the diagonal all 's, and still have the ability to reorder the column.
Define a graph , where and there is an edge from to iff is in . We may assume there is a self loop on each node. Removing those self loops, we will get a simple graph with edges. Let the second act as relabeling the nodes, so it suffices to consider unlabeled graphs. Now, the submatrix condition becomes that:
- For any set of nodes, there exists an edge pointing out.
And is equal to the number of such simple graphs, up to isomorphism.
Clearly, edges does not work. But there is a solution with edges: a cycle plus isolated nodes. Thus, .
Number of Orbits
We can prove this is the only graph.
- If there is a cycle of length , then the rest elements will have only edges. Thus, there exists at least nodes that does not have an outgoing edge. Pick the nodes from the cycle and nodes with 0 outgoing degree, and we get a cut.
- If there is no cycle at all, e.g. forest, then we can simply sort nodes in the topological order and take the last ones.
Thus, . A (somehow) surprising result.
Number of Matrices
Since there is only one orbit, , where is a solution.
Without loss of generality, let contain the cycle plus isolated points . Consider :
- We can reorder the rows in any permutation, as long as we do the same to those columns:
- For the cycle part, the stablizer set size is equal to automorphisms of an unlabeled cycle:
- It's hard to describe why verbally. But you can have a try: pick any row in the cycle to be the first row, and you'll find there are exactly 2 ways to do the rest.
Thus, the total number is .
We can also directly count this:
- For the isolated nodes, we can insert them into any columns & rows:
- And then, we can choose the position to place 1 at each row:
- For the cycle, we can shuffle the rows as a free circular permutation:
- And then each row is different so we can shuffle them:
Thus, the total number is .
PS: Complexity
If the answer is modulo , then we have a faster algorithm via multipoint evaluation. See the next post.
Reference
- Polynomial Algorithms
- Factorial mod Prime in Rust
- 階乗 mod 素数 - memo. Link is broken. Please use Wayback machine.