TITLE: Is this kind of "Gerrymandering" NP-complete?
QUESTION [16 upvotes]: [I posted this on Math Stack Exchange about two weeks ago, but didn't get any reply, so I'm trying it here.]

Consider the following simplified form of "Gerrymandering":  You have $n^2$ squares arranged as an $n\times n$ matrix.  Each square is marked with either $0$ or $1$ which means a "voter preference" for one of two parties.  The task is to divide the set of squares into $n$ subsets of the same size $n$ such that one of the parties, say $1$, has the majority in more than half of the regions - if that's possible at all.  The main geometrical restriction is that each region has to be connected in the sense that two squares are connected if they share a whole edge (and not only a corner).

I wrote a backtracking algorithm to solve this problem which essentially tries all possible ways of assigning connected regions.  It works, but it of course gets much slower as $n$ increases.  I was wondering if this problem (or some variant of it) might be NP-complete.  I would think, though, that to be able to find a polynomial-time reduction of a known NP-complete problem to this one, this problem has to be a bit more general.  Obviously, there are various ways to generalize it:

In its easiest form, the above only works for odd $n$ as for even $n$ there's the chance of a draw.  But one could of course also allow draws and stipulate that, say, you've "won" in a $6\times6$ matrix if you can find three regions with a draw and two where your party wins.
One could require that you have to win by a certain margin: $1$ needs to win at least $k$ more regions than $0$.
The matrix doesn't have to be a square matrix.
The regions don't have to have the exact same size.
More than two parties...

I would want to keep the connectedness restriction, though.
I searched the web to find similar problems but wasn't really successful; maybe I didn't use the right words.  I found some results about the math of Gerrymandering, but they are about different (and more complicated) problems.  I also tried to find known problems that are obviously related to this one, but so far to no avail.  So my questions are:

Is this a known problem (maybe a game or puzzle)?  And if so, what's its name?
If not, does this look similar to a known problem?
Any other hints where to look for more information?

REPLY [5 votes]: This is somewhat complementary to domotorp's existing answer, explaining the first paragraph in more detail.
Let's consider the tightest possible case, where $n = 2m - 1$ and there are $m^2$ A-squares and $n^2 - m^2$ B-squares. The problem is to partition the $n \times n$ grid into $n$ polyominoes of $n$ squares each, such that $m$ of the polyominoes each contain exactly $m$ A-squares and $m-1$ B-squares (and the other $m - 1$ polyominoes contain only B-squares).
Consider the following diagram, where $n = 69$ and $m = 35$:

The red triangle in the upper-left contains $m^2$ squares. The green triangle in the lower-right has the property that there's no polyomino of length $n$ which contains both red and green cells. This means that if the A-squares are entirely contained in the union of the red and green triangles, then they behave as 'disjoint' problems.
That is to say, if we have $m(m-k)$ A-squares in the upper-left (red) triangle and $mk$ A-squares in the lower-right (green) triangle, then solving the full problem is equivalent to covering the A-squares in the upper-left with $m - k$ polyominoes (each containing exactly $m$ of the A-squares) and covering the A-squares in the lower-right with $k$ polyominoes (each containing exactly $m$ of the A-squares).
We'll put the 'interesting' part of the problem entirely in the green lower-right triangle, and just use the upper-left triangle for storing extraneous A-squares.
The side-length of the red triangle is $\frac{1}{\sqrt{2}} n + O(1)$, so the side-length of the green triangle is $(1 - \frac{1}{\sqrt{2}}) n + O(1)$. When $n$ is sufficiently large, this is comfortably larger than $\frac{1}{4}n$. This contains a rectangle of size $a \times b$ provided $a + b \leq \frac{m}{2}$.
Consequently, it suffices to show that we can embed our favourite NP-complete problem as an instance of the following problem:

We have an $a \times b$ rectangle and parameters $k, m$ where $m \geq 2(a + b)$.
The top and left edges of the rectangle are 'open' and the bottom and right edges are 'closed'.
There are $km$ squares marked 'A' inside this rectangle.
The decision problem is to cover the 'A'-squares with $k$ polyominoes of size $2m - 1$, where each polyomino contains $m$ of those 'A'-squares, such that the remaining space is sufficiently connected that it can be covered with polyominoes of the correct size (which are allowed to escape out of the two 'open' edges of the rectangle).

The answer by domotorp gives one approach here. Another approach is to choose $k = 1$ and providing a reduction from the (NP-complete) rectilinear minimum Steiner tree problem. Here's an illustration of how you'd reduce rectilinear minimum Steiner tree to a gerrymandering problem:

We attach the chicane at the bottom to the lowermost point, solely with the purpose of ensuring that there are $m$ A-squares (shown in green) which need to be engulfed in a polyomino using at most $m - 1$ B-squares (shown in red). The chicane packs the desired number of A-squares into a region with side-length $O(\sqrt{m})$, sufficient to ensure that the problem comfortably fits into an $a \times b$ rectangle with $2(a + b) \leq m$.