#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,dp[1<<21],a[25][25];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&a[i][j]);
    dp[0]=1;
    for(int k=0;k<(1<<21)-1;k++){
		int c=0;
		for(int i=0;i<n;i++)if(k>>i&1)c++;
		for(int j=0;j<n;j++)if(!(k>>j&1)&&a[c][j])dp[k^(1<<j)]=(dp[k^(1<<j)]+dp[k])%M;
	}
	printf("%d\n",dp[(1<<n)-1]);
}

