#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint a[25][25];
llint dp[25][1<<21];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	
	llint S = 1<<n;
	dp[0][0] = 1;
	for(int j = 0; j < S; j++){
		int i = 0;
		for(int k = 0; k < n; k++) if(j & (1<<k)) i++;
		for(int k = 0; k < n; k++){
			if(j & (1<<k)) continue;
			if(a[i+1][k] == 0) continue;
			dp[i+1][j|(1<<k)] += dp[i][j];
			dp[i+1][j|(1<<k)] %= mod;
		}
	}
	cout << dp[n][S-1] << endl;
	return 0;
}