Stabbing Number
Time limit2sMemory limit512 MB
Given a histogram polygon drawn in ASCII, find a rectangle decomposition that minimizes the maximum number of rectangles an axis-parallel segment crosses.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Bit manipulation, Geometry
- Solved
- No attempts yet
Problem
A histogram is a simple rectilinear polygon , where the interior angle at each vertex is either or . has a horizontal edge that sees every point inside , including points on its interior and its boundary. An edge sees a point if there is a vertical segment that connects to and lies inside .
Let be a histogram with vertices, and let be a decomposition of into rectangles whose sides are vertical or horizontal. The vertices of the rectangles need not all be vertices of . You may add extra vertices on the boundary of , in its interior, or both.
The stabbing number of a horizontal or vertical segment inside with respect to is the number of rectangles in whose interior (not just their boundaries) intersects. The stabbing number of is the maximum stabbing number of any horizontal or vertical segment inside . Compute a decomposition with the minimum stabbing number.
Input
The first line contains two positive integers and (), the number of rows and columns of the table that shows the histogram. Each of the next lines contains exactly characters. * marks the boundary of the histogram, and the rest of the table is filled with dots (.). Each edge of the histogram contains at least three * characters. The histogram has at least four and at most 16 edges, and no two edges overlap, intersect, or touch. In other words, each * is adjacent to exactly two other * characters.
Output
Print the stabbing number of the given histogram on one line.