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

const int mod = 1e9 + 7;

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> a(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	vector<int> dp(1 << N);
	dp[0] = 1;
	for (int i = 0; i < (1 << N) - 1; i++) {
		int c = __builtin_popcount(i);
		for (int j = 0; j < N; j++) if ((i & (1 << j)) == 0 && a[c][j]) {
			int to = i | (1 << j);
			dp[to] += dp[i];
			if (dp[to] >= mod) dp[to] -= mod;
		}
	}
	cout << dp.back() << endl;
	return 0;
}
