#include <iostream>

using namespace std;

typedef long long ll;

int n;
bool a[25][25];
ll dp[(1 << 22) + 5];
const ll mod = (int)1e9 + 7;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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 mask = 0 ; mask < (1 << n) ; ++mask){
	int i = __builtin_popcount(mask);
	for(int j = 0 ; j < n ; ++j){
		if(!((mask >> j) & 1) && a[i][j]){
			dp[mask | (1 << j)] = (dp[mask | (1 << j)] + dp[mask]) % mod;
		}
	}
}
cout << dp[(1 << n) - 1] << endl;

return 0;
}

