M - Stabbing Number


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Ahistogram is a simple rectilinear polygon HH (i.e. the interior angle at each vertex is either 9090° or 270270°) that has a horizontal edge seeing every point qq inside (i.e. the interior or the boundary of) HH. Here, we say that an edge sees a point qHq \in H if there is a vertical segment ss connecting ee to qq that is lying inside HH.

Let HH be a histogram with nn vertices, and consider a decomposition RR of HH into rectangles whose sides are vertical or horizontal. The vertices of the rectangles need not all be vertices of HH: it is allowed to introduce additional vertices, on the boundary of HH and/or in its interior. The stabbing number of a horizontal or vertical segment ss inside HH with respect to such a decomposition RR is the number of rectangles from RR whose interior (not just their boundaries) are intersected by ss. The stabbing number of RR is the maximum stabbing number of any horizontal or vertical segment ss that lies inside HH. The goal is to compute a decomposition RR with the minimum stabbing number.

ورودی🔗

The first line of the input contains two positive integers mm and nn (1m,n501 \leq m,n \leq 50) denoting the number of rows and the number of columns of the table illustrating the histogram, respectively. The next mm lines, each contains exactly n characters. *s denote the boundary of the histogram. The rest is filled with dots (.). Each edge of the histogram contains at least three *s. You can assume the given histogram has at least four and at most 16 edges, and edges do not overlap, intersect or touch each other; i.e. each * is adjacent to exactly two other * characters.

خروجی🔗

Print the stabbing number of the given histogram in one line.

مثال‌ها🔗

ورودی نمونه ۱🔗

10 13
.....****....
.....*..*....
.....*..***..
.....*....*..
.....*....***
...***......*
...*........*
****........*
*...........*
*************
Plain text

خروجی نمونه ۱🔗

2
Plain text

ورودی نمونه ۲🔗

8 15
...............
.........*****.
....***..*...*.
....*.*..*...*.
.****.****...*.
.*...........*.
.*************.
...............
Plain text

خروجی نمونه ۲🔗

2
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.