#include <bits/stdc++.h>
#define MD 1000000007
using namespace std;
typedef long long ll;
ll dp[1<<22],cp[30][30];
int n;
ll ds(int id, int s) {
	if(id == n) {return 1;}
	if(dp[s] != -1) {return dp[s];}
	ll re = 0;
	for(int i=0;i<n;i++) {
		if(cp[id][i] && !(s & (1<<i))) {
			re += ds(id+1,s|(1<<i));
		}
	}
	return dp[s] = re%MD;
}
int main() {
	scanf("%d ",&n);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			int t;
			scanf("%d ",&t);
			cp[i][j] = t;
		}
	}
	printf("%lld\n",ds(0,0));
}