#include <bits/stdc++.h>
using namespace std;
 int mod = 1e9+7;
 
int main() {
int n;  cin>>n;
 vector< vector< int > >  comp(n+1, vector<int> (n+1));
 for(int i=0; i<n; ++i){
 	for(int j=0; j<n; ++j){
 		cin>>comp[i][j];
 	}
 }
 
 vector<int> dp(1<<n);
 dp[0]=1;
 for(int i=0; i<(1<<n) ; ++i ){
 	int m = __builtin_popcount(i);
 	for(int w=0; w<n; ++w){
 		if( !((i>>w)&1) && comp[m][w]==1 )
 	{	int j = (i|(1<<w));
 		dp[j]+=dp[i]%mod;
 		dp[j]%=mod;
 	}
 	
 	}
 	
 }
 cout<<( dp[(1<<n)-1] + mod)%mod<<'\n';
 
	return 0;
}
