Suppose that we have a grid of size $2n$ by $2n$, with $4n^2$ cells in total. How many ways are there to label each cell in the grid using two labels, say zero and one, such that all ones are orthogonally connected and exactly half of the grid contains ones?
For example, there are four ways to label the grid if $n=1$:
1 1 | 0 0 | 1 0 | 0 1
0 0 | 1 1 | 1 0 | 0 1
Brute force search suggests that there are $1474$ ways to label the grid when $n=2$, here are some examples:
1 1 1 1 | 0 0 1 1 | 1 1 1 1
1 1 1 1 | 0 0 1 1 | 0 1 0 0
0 0 0 0 | 0 0 1 1 | 0 1 0 0
0 0 0 0 | 0 0 1 1 | 1 1 0 0
To clarify, this is what I mean by "orthogonally connected". Let $A$ be a $2n$ by $2n$ matrix representing the grid, let $V = \lbrace (i, j) : A[i,j] = 1 \rbrace$ denote the positions of ones and let $E = \lbrace ((i_1, j_1), (i_2, j_2)) \in V \times V: (i_1, j_1) \in \lbrace (i_2 + 1, j_2), (i_2 - 1, j_2), (i_2, j_2 + 1), (i_2, j_2 - 1) \rbrace \rbrace$. All ones are orthogonally connected whenever the graph $(V, E)$ is connected.
In the examples above, ones are orthogonally connected.
In the following examples, ones are not orthogonally connected.
1 0 0 1 | 1 0 0 0
1 0 0 1 | 0 1 0 1
1 0 0 1 | 0 0 1 0
1 0 0 1 | 1 1 1 1
For reference, here is the python code I used to compute the number 1474. It iterates over $2^{(4n^2)}$ possible ways to fill the grid, and uses scipy.ndimage to detect orthgonally connected components. In the problem, I only consider cases where k is even.
import numpy as np
from scipy.ndimage import label
def count_solutions(k, print_patterns=False):
count = 0
k2 = k * k
for i in range(2**k2):
arr = np.array([int(x) for x in np.binary_repr(i).zfill(k2)]).reshape(k, k)
if label(arr)[1] == 1 and arr.sum() == k2 // 2:
if print_patterns: print(arr)
count += 1
return count
(Here I'm assuming an $n\times n$ grid rather than $2n\times 2n$, to more easily talk about odd-sized grids.)
I've written a program to compute a few more of these numbers (source code below). Using dynamic programming, it is possible to compute the answer in $O(n! 2^{n})$ time, which is a bit better than the $O(2^{n^2})$ naive enumeration. The basic idea is to work one row of the grid at a time: the possible states of each row can be encoded by (1) whether each entry of the row is a $0$ or a $1$; (2) one color for each of the $1$s, where two $1$s have the same color if they are connected by an orthogonal path of $1$s contained in rows $1\leq j \leq i$.
The number of valid ways to fill the grid is thus the number of ways to fill $j$ rows ($j \leq n$) with $n^2/2$ ones that all have the same color in the final row.
I'm not seeing any patterns and the sequence is not in OEIS, so I'm rather pessimistic there's a nice closed form.
Here are some numbers for $n$ odd, if we requires $\lfloor n^2/2\rfloor$ ones:
Source code: