#include <iostream>
using namespace std;
typedef long long ll;

int N,A[22][22];
ll inf = 1e9+7,dp[1<<21];

int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> A[i][j];
		}
	}
	dp[0] = 1;
	for(int i=0;i<N;i++){
		for(int S=0;S<(1<<N)-1;S++){
			if(i!=__builtin_popcount(S)) continue;
			for(int j=0;j<N;j++){
				if(!(S & (1<<j)) && A[i][j]){
					(dp[S|(1<<j)] += dp[S])%=inf;
				}
			}
		}
	}
	cout << dp[(1<<N)-1] << endl;
}