14025 - Let the Queen cooks   

Description

I loved the part when she said “It’s cooking time!” And cooks everywhere, it really shows that she really cooks all the time.

Pin on Bakery logo design

Given a n x n board, each tile is either 1 or 0, you need to put n queens and count how many solutions are legal as the rules:

  • 0 means you can put the queen in that tile.
  • 1 means the tile is occupied, and we can't put the queen there.
  •  Queens can't attack each other, therefore each row, column, and diagonal has only 1 queen.

For example, the answer of the sample input is 1 as the picture below speaks for itself. There is no other possible move.

Little help from the queen: use scanf("%1d") to scan 1 digit number.

Input

First line is an integer n (1 <= n <= 10)

The next n lines is the board state, each n digit, consist only number 1 and 0.

It's guaranteed that every row has atleast 1 number 0

Output

Output an integer with how many solution the input has.

Following with '\n'

Sample Input  Download

Sample Output  Download

Tags




Discuss