Each column in A satisfying condition (a) can be identified with a partition of the set \(\left\{1,\ldots,n\right\}\) into 1,2 or 3 subsets, depending on how many of \(\left\{0,1,-1\right\}\) are used in filling the column. Because of the previous condition, the partition associated with each column must be the same.
Case 1: All element of the first column of A are equal. Then all elements of each other column of A must also be equal. There are 3 choices of value for each column, and all possible choices are allowable, so the choices are independent. Thus \(3^n\) matrices A of this type.
Case 2: The elements in the first column of A are \(\left\{0,1\right\}\) or \(\left\{0,-1\right\}\). Let Stirling(n,k) be the Stirling number of the second kind. There are Stirling(n,2)=\(2^{n-1}-1\) ways of partitioning the first-column elements of A, and then 4 ways of assigning the partitions to \(\left\{0,\pm1\right\}\). Once the first column of A is filled, the partitioning of the second column is determined and there are 2 valid ways of assigning the partitions to \(\left\{0,\pm1\right\}\). Same is true of the next n-2 columns. Thus there are \(\left(2^{n-1}-1\right)\cdot4\cdot2^{n-1}\) matrices of this type.
Case 3: The elements in the first column of A are chosen from \(\left\{\pm1\right\}\). There are Stirling(n,2)=\(2^{n-1}-1\) ways of partitioning the first-column elements of A. There are 2 ways of assigning values to the partitions to the values \(\left\{\pm1\right\}\). Thenceforth, the values of A in the remaining columns are completely determined (all columns must be the same). Thus there are \(2^n-2\) matrices are this type.
Case 4: The set of elements of the first column are the full set \(\left\{0,1,-1\right\}\). There are Stirling(n,3)=\(\frac{1}{2}\left[3^{n-1}+2^n+1\right]\) ways of partitioning the entries of the first column of A and, for each partition, \(3!=6\) ways of assigning the 3 partitions to the set of values \(\left\{0,1,-1\right\}\) . Then the only way to fill the rest of A is for all entries in each column to be equal to the entries in the previous. So there are a total of \(3\cdot\left[3^{n-1}+2^n+1\right]\) such matrices.
So the total number of such matrices is \(4_{ }^n+2\cdot3^n+2\cdot2^n+1\).