Find solution

How can I find the minimum number of open rectangles in a grid?

Check our answers to ‘How can I find the minimum number of open rectangles in a grid?’ - we found 17 replies and comments relevant to this matter. The best answers are submitted by users of Stack Overflow, Yahoo! Answers and Quora.

Best solution

  • Find minimum number of rectangles of length 2 in a grid of binary values

    Given a grid, I need to "cover" the true values with rectangles. The rectangles can only be horizontal or vertical and they can cover two cells at max. For example, in this case: 1 1 1 0 0 1 0 0 0 1 0 0 0 1 0 the minimum number of ractangles is 4: 1 from [0][0] to [1][0], 2 from [0][1] to [0][2], 3 with only [1][4] (since there aren't any adjacent 1s in the up, down, left and right directions) and the last one with only [2][3] in it. I suppose, the problem comes when the grid has many...

    Answer:

    I would simply go through the matrix and as soon I see a 1 I try to create a new rectangle with an adjacent...

    Mark as irrelevant Undo

Other solutions