#include <iostream>
#include <vector>

using namespace std;

#define MOD 1000000007

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<long long> dp(1 << n);
	dp[0] = 1;
	for (int i = 0; i < (1 << n); ++i) {
		int cnt = __builtin_popcount(i);
		for (int j = 0; j < n; ++j)
			if (!(i & (1 << j)) && a[cnt][j])
				(dp[i | (1 << j)] += dp[i]) %= MOD;
	}
	cout << dp[(1 << n) - 1] << endl;

	return 0;
}