chess is a two-player board the game believed to have been India as early as the sixth century. However, in this problem we are not discuss about chess, rather we'll talk about a modified form of the classic N-queen Problem. I know you are familiar with plotting n-queens on a chess board with the help of a classic backtracking. If you write this algorithm now you'll find this there are ways of plotting 8 Queens In a 8x8 board provided no Queens attack each of the other.
In this problem we'll talk about injured queens who can move only like a king in horizontal and diagonal direction from Current position but can reach any row from the position like a normal chess queen. You'll have to find the number of possible arrangements with such injured Queens in a particular (n x N) board (with some additional constraints), such that no two queens all other.
|
| Fig: Injured Queen at A6 can reach the adjacent grey squares. Queen atE4 can reach adjacent grey squares. The injured Queen positions are black and reachable places, are grey. |
Input
Input file contains several lines of input. Each line expresses a certain board status. The length of these are status string is the board dimension N (0<n<=15) . The ' the ' of the ' denotes ' of the ' the ' the ' the ' of the ' the ' of the ' the ' of the ' the second character S of the second column and so on. So if the character of the status string is 2 , it means that we are looking for arrangements (no TW O injured Queen attack each other) which has injured queen in column A, row 2 . The possible numbers for rows are 1, 2, 3 ... D, E, F which indicates row 1, 2, 3 ... A . If any column contains ' ? ' It means the injured queen can is in any row. So a status string 1?4?? 3 means, are asked to find out total number of possible arrangements in a (6x6) Chessboa Rd which has three of its six injureD Queens at A1 , C4 and F3 . Also Note that there would be no invalid inputs. For example 1?51 are a invalid input because a (4x4) chessboard does not have a fifth R ow.
Output
For each line of the input produce one line of output. This line should contain a integer which indicates the total number of possible arrangements of the corresponding input s Tatus string.
Sample Input
??????
???????????????
??? 8?????
?????
Sample Output
2642
22696209911206174
2098208
0