0

How many (at most) 1x2 (or 2x1) zeroed submatrices fits in NxN binary matrix?

For:

1 0 0
0 0 0
0 1 0

result will be 3.

For:

0 0 1 0 0 1 0 0 0
0 1 0 1 0 1 0 1 1
1 0 0 1 0 1 1 0 1
0 1 1 0 1 0 1 0 0
0 0 0 0 1 0 1 1 0
1 1 1 1 0 0 1 0 0
1 0 0 1 1 1 1 1 1
0 0 1 1 0 0 0 0 0
1 0 0 1 0 0 1 1 0

result will be 21.

And so on.

Piotr Jedyk
  • 361
  • 1
  • 10
  • What is your question? Are you testing us to see if we can solve these puzzles? Or perhaps you want us to just write your code for you? The idea is that you try to solve the problem and, if you run into some trouble with the code, you ask *specific questions*, showing us what you've done and what you're having trouble with. – Jim Mischel Oct 27 '17 at 19:25

1 Answers1

0

This may not be the most efficient approach, but one simple way to solve this is via computing a maximum bipartite matching, e.g. with the Hopfield-Karp algorithm.

The key is to think of the grid as a chessboard, each of your shapes will connect one black square with one white square.

Generate a graph with one left node for each black square, one right node for each white square, and one edge from a black square node to all neighbouring white square nodes.

The maximum matching in this graph will be the answer to the maximum number of non-overlapping dominos that can be placed in your grid.

Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75