A grid has N horizontal lines and M vertical lines, so it has N×M intersection points. You put stones on some of the intersection points, and you want at least K points to end up enclosed.
An intersection point is enclosed if either of the following holds.
- A stone sits on the point.
- Starting from the point, moving along the grid lines to neighboring points and stepping only on points that hold no stone, you cannot reach an empty point on the border of the grid.
Find the smallest number of stones that leaves at least K enclosed points.
For example, enclosing 8 points on a 4×5 grid takes at least 6 stones. The picture below shows one such placement. Enclosed points are marked with an x.
