#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
ll a[25][25];
ll dp[25][1<<21];
ll n;
ll func(ll i,ll mask)
{
	//cout<<i<<" "<<mask<<endl;
	ll sum=0,j;
	if(i>n)
		return 1;
	if(dp[i][mask]!=-1)
		return dp[i][mask];
	for(j=1;j<=n;j++)
	{
		if(a[i][j]&&!(mask&(1<<(j-1))))
			sum=(sum+func(i+1,mask^(1<<(j-1))))%mod;
	}
	dp[i][mask]=sum;
	return dp[i][mask];
}
int main()
{
	ll i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			cin>>a[i][j];
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=1<<n;j++)
			dp[i][j]=-1;
	}
	cout<<func(1,0)<<endl;
}
