I would like to know a few things about the algorithm for the following problem: Given a matrix with 0s and 1s and the size of a square, what is the maximum number of adjacent squares for covering the 1s and what is their position? In case there are several possible square combinations, just output one.
EX: For a size of 2:
Input:
0 0 1 0 0 0
0 1 1 1 1 0
0 0 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 0 0 0
Possible output: Maximum 3 squares (each marked with a letter)
0 0 1 0 0 0
0 1 a a 1 0
0 0 a a 1 0
0 b b c c 0
0 b b c c 0
0 1 1 0 0 0
I would like to know if a polynomial (or pseudo-polynomial) algorithm for the optimum solution exists. If yes, what is the algorithm and its asymptotic complexity? If not, what approximation algorithm should I use?
Also, you can assume, that there are no 'islands' of 0s inside the areas of 1s if this makes the problem easier, so the following case should not be encountered:
1 1 1
1 0 1
1 1 1
I am an amateur programmer and this is my first question here. It would be very useful for me if your answer would also suggest an area of study for this algorithm. Thanks in advance.