Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10551 Accepted Submission(s): 6216
Problem Description
Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.
A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.
Here we assume that a bullet is so powerful thatit can run across any distance and destroy a blockhouse onits way. On the other hand, a wall is so strongly built that can stop the bullets.
The goal isto place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are onthe same horizontal row or vertical column in a map unless there isat least one wall separating them. In this problem we will consider small square cities (at most 4x4) thatcontain walls through which bullets cannot runthrough.
The following image shows five pictures ofthe same board. The first picture isthe empty board, thesecondandthird pictures show legal configurations, andthefourthandfifth pictures show illegal configurations. For this board, the maximum numberof blockhouses in a legal configuration is5; thesecond picture shows one way to do it, but there are several other ways.
Your task istowrite a program that, given a description of a map, calculates the maximum numberof blockhouses that can be placed inthe city in a legal configuration.
Input
The input filecontains one or more map descriptions, followed by a line containing thenumber0that signals theendofthefile. Each map description begins with a line containing a positive integer n thatisthe size ofthe city; n will be at most 4. The next n lines each describe one row ofthe map, with a '.' indicating an open spaceand an uppercase 'X' indicating a wall. There are no spaces inthe input file.
Output
For each test case, output one line containing the maximum numberof blockhouses that can be placed inthe city in a legal configuration.
Sample Input
4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0
Sample Output
51524