I have a $n\times n$ matrix of objects. $n'$ objects are black, and the rest $n^2-n'$ are white.
With that information, I can easily calculate the total number of black element arrangements that exist in the 2D matrix by using basic combinatorics: $C(n^2, n')$
Given the number of black elements present in the matrix, I aim to calculate the number of possible arrangements of those $ n'$ elements that contain at least one path from top to bottom of the grid (or vice-versa). However, I didn't find any direct formula or expression that relates $n^2$ and $n'$ to get that number.
How can I approach this problem without making an estimation or a simulation to obtain the number?
Edit: Consider a path from top to bottom in the matrix as a sequence of colored elements with the first one positioned in the first row of the grid and the last one in the corresponding opposite (last) row. For every contiguous pair of elements in the sequence, their distance must be 0; that is, they must be neighbors horizontally, vertically, or diagonally, and there is no limit or restriction for a path's length.
Also, note that this path definition doesn't include those whose starting and ending points are in the first-last columns of the grid.