This problem appeared in a challenge, but since it is now closed it should be OK to ask about it.
The problem (not this question itself, this is just background info
Dynamic programming: choose a cell (any cell will do), compute all valid squares that cover it (that is, that only cover the current cell and other cells in the grid). For each such square, recursively get the minimum coverage value for the remaining area (grid minus the square), and then choose the minimum value from those (the result is that value + 1). To make things faster, try to choose a cell which has the fewest valid covering square in each level of the recursion (thus reducing the number of recursive calls in each level).
Simple really.