ICPC 2011 World Finals · Problem D
A prominent microprocessor company has enlisted your help to lay out some interchangeable components (widgets) on some of their computer chips. Each chip’s design is an N × N square of slots. One slot can hold a single component, and you are to try to fit in as many widgets as possible.
Modern processor designs are complex, of course. You unfortunately have several restrictions:
A specification for a chip is N lines of N characters, where ‘.’ indicates an open slot, ‘/’ indicates a disabled slot, and ‘C’ indicates a slot already occupied by a component. For example:
CC/.. ./.// ..C.C /.C.. /./C/
If no more than 3/10 of the components may be in any one row or column, the maximum number of widgets that can be added to this 5 × 5 chip is 7. A possible arrangement is below, where ‘W’ indicates a widget added in an open slot.
CC/W. W/W// W.C.C /.CWW /W/C/
The input consists of several test cases. Each case starts with a line containing three integers: The size of the chip N (1 ≤ N ≤ 40), and A and B (1 ≤ B ≤ 1000, 0 ≤ A ≤ B) as described above. Each of the following N lines contains N characters describing the slots, one of ‘.’, ‘/’ or ‘C’, as described above.
The last test case is followed by a line containing three zeros.
For each test case, display a single line beginning with the case number. If there is a solution, display the maximum number of widgets that can be added to the chip. Display “impossible” if there is no solution.
Follow the format of the sample output.
2 1 1 /. // 2 50 100 /. C/ 2 100 100 ./ C. 5 3 10 CC/.. ./.// ..C.C /.C.. /./C/ 5 2 10 CC/.. ./.// ..C.C /.C.. /./C/ 0 0 0
Case 1: 0 Case 2: 1 Case 3: impossible Case 4: 7 Case 5: impossible