#include <bits/stdc++.h>
using namespace std;

const int N = 21;
const int MOD = 1e9 + 7;

int n, a[N][N], dp[N][1 << N];

int f(int i, int mask) {
	if (i == n)
		return 1;
	
	int& ret = dp[i][mask];
	if (ret != -1)
		return ret;
	
	ret = 0;
	for (int j = 0; j < n; j++)
		if (a[i][j] and !(mask & (1 << j)))
			ret = (ret + f(i + 1, mask | (1 << j))) % MOD;
	
	return ret;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	
	memset(dp, -1, sizeof dp);
	cout << f(0, 0) << '\n';
	return 0;
}