#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define modp(x) ((x)%modn)
using namespace std;
const int maxn=25;
const ll maxm=1<<22,modn=1e9+7;
bool a[maxn][maxn];
ll f[maxm],n,m;
int main()
{
	cin>>n;m=(1<<n)-1;
	rep(i,0,n-1) rep(j,0,n-1) cin>>a[i][j];
	f[0]=1;
	rep(i,1,m)
	{
		int cnt=-1;
		rep(j,0,n-1) if(i&(1<<j)) cnt++;
		rep(j,0,n-1) if((i&(1<<j)) && a[cnt][j]) f[i]=modp(f[i]+f[i^(1<<j)]);
	}
	cout<<f[m];
	return 0;
}