Combinatorics and Matrices Find the number of $4\times4$ matrices such that $|a_{ij}| = 1 \forall i,j\in[1,4]$ , and sum of every row and column is zero.
I tried 'counting' the number of matrices that satisfy the above conditions, that is, elements are $1$ or $-1$ and sum of every row and column is zero.
In the attempt to generate a recursion I started off with a $2\times2$ matrix, for which case the answer is $2$. (First element is 1 or -1, other elements are decided accordingly) 
However, this method becomes cumbersome and mathematically disappointing for $3x3$ and larger matrices.
Could someone please explain the method, or post a solution to the problem? 
Is it possible to generalise the result to an nxn matrix? 
 A: The first row has two $1$s and two $-1$s. There are $\binom{4}{2} = 6$ ways they can be arranged in the first row. We'll count the number of matrices with first row $(1,1,-1,-1)$, then multiply by $6$ to account for all the other arrangements of the first row.
The second row can be one of the three following things: $(1,1,-1,-1)$, or $(-1,-1,1,1)$, or $(1,-1,1,-1)$. In the third case this counts for $4$ possibilities: the first two columns might be switched, or the last two columns might be switched. We'll count the number of matrices in each of these three cases (multiplying the third cases's count by $4$, to account for the switches).
Case 1: The matrix looks like
$$
  \begin{pmatrix}
    1 & 1 & -1 & -1 \\
    1 & 1 & -1 & -1 \\
    * & * & * & * \\
    * & * & * & *
  \end{pmatrix}
$$
There is only one possible matrix:
$$
  \begin{pmatrix}
    1 & 1 & -1 & -1 \\
    1 & 1 & -1 & -1 \\
    -1 & -1 & 1 & 1 \\
    -1 & -1 & 1 & 1 \\
  \end{pmatrix}
$$
Case 2: The matrix looks like
$$
  \begin{pmatrix}
    1 & 1 & -1 & -1 \\
    -1 & -1 & 1 & 1 \\
    * & * & * & * \\
    * & * & * & *
  \end{pmatrix}
$$
In the last two rows, there is precisely one $-1$ in each column and two $-1$s in each row. There are $\binom{4}{2}=6$ ways to choose the locations of two $-1$s in the third row; then the fourth row is determined (it has $-1$s in the complementary positions).
Case 3: The matrix looks like
$$
  \begin{pmatrix}
    1 & 1 & -1 & -1 \\
    1 & -1 & 1 & -1 \\
    * & * & * & * \\
    * & * & * & *
  \end{pmatrix}
$$
The first and last columns are determined:
$$
  \begin{pmatrix}
    1 & 1 & -1 & -1 \\
    1 & -1 & 1 & -1 \\
    -1 & * & * & 1 \\
    -1 & * & * & 1
  \end{pmatrix}
$$
There are two solutions: the remaining block can be $\begin{pmatrix} 1 & -1 \\ -1 & 1 \end{pmatrix}$ or the opposite. That gives two solutions when the second row is as displayed, but because of the possibility of switching the first two or last two columns, we count $8$ solutions.
Subtotal: With this first row, we have $1+6+8=15$ matrices.
Total: There are $6$ equivalent arrangements of the first row, so we have $6 \cdot 15 = 90$ matrices in total.
It seems unlikely that this kind of approach could generalize to larger matrices.
A: This is quite difficult to generalize to a $n \times n$ matrix. I would suggest generalizing to having two $1$'s in each row and column in an $n \times n$ matrix, as is done is problem $8$ of combinatorics in 2012 February HMMT. The recursion developed in the official solution solves your problem for $n=4$.
There is also a slightly simpler way of constructively counting it for the $4 \times 4$ problem. First we split the types into two cases.
The first is where we have two pairs of matching columns, as
$$\begin{bmatrix}
1 & -1 & 1 & -1 \\
1 & -1 & 1 & -1 \\
-1 & 1 & -1 & 1 \\
-1 & 1 & -1 & 1
\end{bmatrix}$$
We can count how many of these there are by first choosing two $1$'s out of $4$ spaces for the first column, and then $1$ from the next $3$ columns to replicate the first column. 
$$\binom{4}{2} \binom{3}{1} = 18$$
The second case is where we have no repeated columns, as
$$\begin{bmatrix}
1 & -1 & \color{red}1 & -1 \\
1 & \color{red}1 & -1 & -1\\
-1 & \color{red}1 & -1 & 1\\
-1 & -1 & \color{red}1 & 1
\end{bmatrix}$$
Again we can start counting these by choosing two $1$'s out of $4$ spaces for the first column. Then we have two choices of pairing the $1$'s in the columns that share a $1$ row with the first column, which is represented in red to make it easier to see. Finally we have $3!$ ways of arranging the second three columns. Multiplying these together we have
$$\binom{4}{2} \cdot 2 \cdot 3! = 72$$
And finally we add the two cases to get $18+72 = \color{red}{90}$.
A: And here is a tour of the HMMT solution for the generalized version, for posterity and for understanding.
The problem statement is now as follows: "Find the amount of $n \times n$ matrices do there exist for which all the columns and rows contain exactly two $1$'s and the rest of numbers are $-1$'s"
The first paragraph explains an important concept vital to the solution of the problem which involves cycles. A cycle of length $n$ is a permutation of objects $a_i$ where $a_{k_1}$ maps to $a_{k_2}$, $a_{k_2}$ maps to $a_{k_3}$, and so on until we have $a_{k_n}$ mapping back to $a_{k_1}$ where all $n$ $k_i$'s are distinct.
Now, when we look at the $n \times n$ matrix colored with cycles in mind. We can see that there exist parts of the matrix which trace out a path which maps to a cycle. As an example, this $5 \times 5$ matrix contains two cycles. One of length $2$ and one of length $3$.
$$\begin{bmatrix}
\color{blue}1 & \color{blue}1 & -1 & -1 & -1 \\
-1 & \color{blue}1 & -1 & \color{blue}1 & -1 \\
-1 & -1 & \color{red}1 & -1 & \color{red}1 \\
\color{blue}1 & -1 & -1 & \color{blue}1 & -1 \\
-1 & -1 & \color{red}1 & -1 & \color{red}1 
\end{bmatrix}$$
For a $n \times n$ matrix, we can count the number of ways to create the matrix by creating a $k$ sized cycle and then filling in the rest  with an $(n-k) \times (n-k)$matrix. If we denote the number of matrices of size $n \times n$ as $f(n)$ as is done in the HMMT solution, we can sum over all the different length cycles (of length at least $2$!) to get
$$f(n) = \sum_{k=2}^n a_kf(n-k) \tag{1}$$
Where $a_k$  is the number of ways to create a $k$ cycle in an $n \times n $ matrix. So now we must find $a_n$.
The easiest way to do this is as is done in the HMMT solution. Looking at the first column, we have $\binom{n}{2}$ ways of choosing the first two squares. Now we choose the second column. There are $n-1$ ways of choosing the second column, and $n-2$ ways of choosing the second $1$ in that column (if $n>2$). Then $n-2$ ways of choosing the third column and $n-3$ ways of choosing the second $1$ in that column (if $n>3$). Note that we start out from only one of the two squares in the first column to avoid over-counting.
We can see that this pattern countinues on until we choose the final column from $n-k+1$ remaining columns, and the second square must align with the other of the first two squares. Thus we have the formula
$$a_k = \frac{n(n-1)}{2} \times (n-1)(n-2) \times ... \times (n-k+1) = 
\frac{n!(n-1)!}{2(n-k)!(n-k)!} \tag{2}$$
Combining $(1)$ and $(2)$, we get the formula from the official solution
$$f(n) = \sum_{k=2}^{n}\frac{1}{2} f(n-k) \frac{n!(n-1)!}{(n-k)!(n-k)!}$$
Then some rearranging to get
$$\frac{2nf(n)}{n!n!} = \sum_{k=2}^{n} \frac{f(n-k)}{(n-k)!(n-k)!}$$
And finally a trick to get rid of the summation
$$\frac{2nf(n)}{n!n!} - \frac{2(n-1)f(n-1)}{(n-1)!(n-1)!} = \sum_{k=2}^{n} \frac{f(n-k)}{(n-k)!(n-k)!} - \sum_{k=2}^{n-1} \frac{f(n-k)}{(n-k)!(n-k)!} \\
\frac{2nf(n)}{n!n!} - \frac{2(n-1)f(n-1)}{(n-1)!(n-1)!}=\frac{f(n-2)}{(n-2)!(n-2)!}$$
Finally, multiplying each side by $n!n!/2n$, we get our recursion for the solution to the generalized problem.
$$f(n) = (n)(n-1)f(n-1) + \frac{n(n-1)^2}{2}f(n-2)$$
And applying this, with $f(1) = 0$ and $f(2) = 1$, we get the following results, including $90$ for $n=4$, as expected.
$$f(3) = 6$$
$$\color{red}{f(4) = 90}$$
$$f(5) = 2040$$
$$f(6) = 67950$$
And here is the OEIS sequence https://oeis.org/A001499
