دیجیکالا تعداد زیادی انبار در مکانهای مختلف دارد. در یکی از شبها دزدی وارد یکی از انبارهای دیجیکالا شده و چند جعبه از انبار خارج کرده است. از آنجا که این دزد بسیار باهوش بوده به شکلی این کار را انجام داده است که از راه دوربینهای انبار قابل ردیابی نباشد. در این سوال میخواهیم بدانیم اگر به همین شکل از بقیهی انبارها دزدی شود حداکثر چند جعبه میتواند از هر انبار خارج شود. فرض کنید هر انبار یک مستطیل n×m است که میتوان با یک ماتریس تعداد جعبههای هر خانه را نشان داد. همچنین فرض کنید هر شب از هر انبار سه عکس گرفته میشود؛ از جلو، بغل و بالا.
برای مثال برای انبار زیر:
ماتریس انبار
این عکسها گرفته میشود:عکسهای انبار
و یک دزد میتواند از این انبار به شکل زیر حداکثر ۹ جعبه را بردارد و بقیه را طوری جابجا کند که از دوربینها همان عکسهای بالا گرفته شود.
بعد از دزدی!
ورودی
در اول خط اول ۲ عدد صحیح r و c که به ترتیب طول و عرض انبار هستند داده میشود. در r خط بعدی در هر خط c عدد داده میشود که هر کدام تعداد جعبهها هستند.
1
≤
c
,
r
≤
100
1≤c,r≤100
خروجی
در خروجی بیشترین جعبهای که میتواند از انبار خارج شود طوری که از عکس دوربینها مشخص نباشد را چاپ کنید.
مثال
ورودی نمونه ۱
5 5
1 4 0 5 2
2 1 2 0 1
0 2 3 4 4
0 3 0 3 1
1 2 2 1 1
Plain text
خروجی نمونه ۱
9
Plain text
ورودی نمونه ۲
2 3
50 20 3
20 10 3
Plain text
خروجی نمونه ۲
30
Assistant
To determine the maximum number of boxes that a thief can steal from a DiJiKala warehouse without being detected by surveillance cameras, we need to analyze the warehouse's box distribution and its projections from different viewpoints (front, side, and top). Here's a step-by-step approach to solve the problem:
1. Understanding the Projections:
Front View: Represents the maximum number of boxes in each column.
Side View: Represents the maximum number of boxes in each row.
Top View: Indicates which cells have boxes (non-zero) and which do not (zero).
2. Objective:
The goal is to minimize the total number of boxes remaining in the warehouse after the theft while ensuring that the projections (front, side, and top) remain unchanged.
3. Steps to Determine the Maximum Stolen Boxes:
a. Calculate Projections:
Row Maximums (R): For each row, find the maximum number of boxes. This ensures that from the side view, the maximum height is maintained.
Column Maximums (C): For each column, find the maximum number of boxes. This ensures that from the front view, the maximum height is maintained.
b. Calculate the Original Total Boxes:
Sum all the boxes present in the warehouse matrix.
c. Determine the Minimal Required Boxes After Theft:
To maintain the projections:
Each cell with an original box count greater than zero must have at least one box remaining.
For each row and column, ensure that at least one cell meets the row and column maximums respectively.
This involves:
Assigning the maximum required boxes to certain cells to satisfy both row and column constraints.
Minimizing the number of boxes in other cells by setting them to 1.
d. Optimize Box Assignments:
To achieve the minimal total:
Overlap Assignments: Assign certain cells to satisfy both row and column maximums simultaneously where possible. This reduces the total number of boxes needed.
Maximum Weight Matching: Formulate this as a bipartite graph where rows and columns are nodes, and edges exist if a cell has boxes. Assign weights based on the minimum extra boxes required, and find the optimal matching that maximizes savings.
e. Calculate Maximum Stolen Boxes:
Subtract the minimal required total boxes from the original total to get the maximum number of boxes that can be stolen without altering the projections.
After performing the calculations and optimizing the assignments:
Minimal Required Total: 36 boxes.
Maximum Stolen Boxes: 45 - 36 = 9
Sample Input 2:
code
2 3
50 20 3
20 10 3
Original Total: 106 boxes.
Row Maximums (R): [50, 20]
Column Maximums (C): [50, 20, 3]
Number of Positive Cells: 6.
After calculations:
Minimal Required Total: 76 boxes.
Maximum Stolen Boxes: 106 - 76 = 30
Conclusion:
By methodically calculating the projections and optimizing the remaining boxes to satisfy these projections, we can determine the maximum number of boxes that can be stolen without being detected.