#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MD=1e9+7;
const int M=22;
int mat[21][21],n;
int dp[(1<<M)];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<n;j++)
		scanf("%d",&mat[i][j]);
	}
	dp[0]=1;
	for(int msk=1;msk<(1<<n);msk++)
	{
		int cnt=__builtin_popcount(msk);
		for(int j=0;j<n;j++)
		{
			if(mat[cnt][j] && (msk&(1<<j)))
			dp[msk]=(dp[msk]+dp[msk^(1<<j)])%MD;
		}
	}
	printf("%d",dp[(1<<n)-1]);
	return 0;
}