#P3182. [HAOI2016] 放棋子

[HAOI2016] 放棋子

Description

Given an N×NN\times N matrix. Each row contains exactly one obstacle; it is guaranteed that no two obstacles are in the same row or the same column. You need to place NN pieces on this matrix (you cannot place a piece on a cell with an obstacle) such that each row contains exactly one piece and each column contains exactly one piece. Find the number of valid arrangements.

Input Format

The first line contains an integer NN, followed by an N×NN \times N matrix. N200N\leq 200. 00 denotes no obstacle, and 11 denotes an obstacle.

Output Format

A single integer, the number of valid arrangements.

2
0 1
1 0
1

Hint

Translated by ChatGPT 5