A hypothetical function F takes a two-dimensional grid and gives a grid of one fewer row and column.
The following transformation takes place in this hypothetical function
Value of grid[i][j] can be converted to 1 by transformation if and only if values in ONE of the element grid[i][j], grid[i][j+1], grid[i+1][j] or grid[i+1][j+1] is 1. If more than one element from those elements are 1, then grid[i][j] will be 0 after transformation.
So, for example
0 1 0 0
0 0 1 0
0 0 0 1
1 0 0 0
can be transformed into another grid given below by function F
1 0 1
0 1 0
1 0 1
Given F(X)=Y, I want to find distinct number of X grids possible for the given grid Y. For the above example, number of X possible is equal to 4.
How can I solve questions of such types? Is there any theory to solve such questions?