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

LL n, mod = 1000000007;
LL dp[21][(1<<21)], a[22][22];

LL solve(int pos, int bit) {
	if(pos == n) return 1;
	LL &ret = dp[pos][bit];
	if(ret != -1) return ret;
	ret = 0;
	for(int i = 0; i < n; i++) {
		if(a[pos][i] && !(bit&(1<<i))) {
			ret = (ret + solve(pos+1, bit|(1<<i))) % 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<<solve(0, 0)<<endl;
	return 0;
}
