#include <bits/stdc++.h>

using namespace std;

const int maxn = 21;
const int mod = 1e9+7;

int n, a[maxn][maxn], s[1<<maxn];
long long int dp[1<<maxn];

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}

	for (int i = 1; i < (1<<n); i++){
		s[i] = s[i-(i&(-i))] + 1;
	}

	dp[0] = 1;
	for (int mask = 1; mask < (1<<n); mask++){
		for (int i = 0; i < n; i++){
			if (((1<<i) & mask) && a[i][s[mask]-1])
				dp[mask] = (dp[mask] + dp[mask^(1<<i)]) % mod;
		}
	}

	cout << dp[(1<<n)-1] << endl;
	return 0;
}
