#include<iostream>
#define mod (int(1e9)+7)
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n][n];
	long long b[1<<n];
	b[0]=1;
	fill(b+1,b+(1<<n),0);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>a[i][j];
	for(int i=1;i<(1<<n);++i)
	{
		for(int j=0;j<n;++j)
			if(((i>>j)&1)&&a[__builtin_popcount(i)-1][j]==1)
			{
				b[i]+=b[i-(1<<j)];
				b[i]%=mod;
			}
	}
	cout<<b[(1<<n)-1];
}