#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int>inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int>inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 118;
const bool TESTCASES = 0;
const bool CODEJAM = 0;
struct modll{using X = int; X v=0;operator X(){return v;}modll(){}modll(int n){v=n;}modll(ll n){v=n;};
modll operator+(ll b){ll ret=v+b;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator+(int b){ll ret=v+b;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator+(modll b){X ret=v+b.v;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator-(ll b){ll ret=v-b;if(ret<0)ret+=MOD;return {ret};}
modll operator-(int b){ll ret=v-b;if(ret<0)ret+=MOD;return {ret};}
modll operator-(modll b){ll ret=v-b.v;if(ret<0)ret+=MOD;return {ret};}
modll operator*(ll b){ll ret = (v*b)%MOD;return {ret};}
modll operator*(int b){ll ret = (v*b)%MOD;return {ret};}
modll operator*(modll b){ll ret = (v*b.v)%MOD;return {ret};}
modll &operator+=(modll b){v+=b.v;if(v>=MOD)v-=MOD;return*this;}
modll &operator-=(modll b){v-=b.v;if(v<0)v+=MOD;return*this;}
modll &operator*=(modll b){v=v*b.v%MOD;return*this;}
modll &operator++(int){v++;if(v>=MOD)v-=MOD;return*this;}
modll &operator--(int){v--;if(v<0)v+=MOD;return*this;}
modll inv(modll &x,int y){if(y==0)return {1};
modll p=inv(x,y/2);p=p*p;return(y%2==0)?p:(x*p);}
modll operator/(modll b){return {(v*inv(b,MOD-2))%MOD};}
modll operator/(int b){modll t=b;return{(v*inv(t,MOD-2))%MOD};}
modll operator/(ll b){modll t=b;return{(v*inv(t,MOD-2))%MOD};}
modll &operator/=(modll b){v*=inv(b,MOD-2);return*this;}
friend istream &operator>>(istream &in, modll &c){in>>c.v;return in;}};

void solve() {
	int n;
	cin >> n;
	int allmask = (1 << n);
	vector<vector<bool>> m(n, vector<bool>(n));
	for(int i = 0; i < n; i++) for(int j = 0, p; j < n; j++) {
		cin >> p; m[i][j] = p;
	}
	vector<vector<modll>> dp(n + 1, vector<modll>(allmask, 1));
	for(int i = 1; i <= n; i++) {
		for(int mask = 0; mask < allmask; mask++) {
			if(i != __builtin_popcount(mask)) continue;
			modll ret = 0;
			for(int j = 0; j < n; j++) {
				if(m[i - 1][j] and (mask >> j) & 1) {
					int newmask = mask & ~(1 << j);
					ret += dp[i - 1][newmask];
				}
			}
			dp[i][mask] = ret;
		}
	}
	cout << dp[n][allmask - 1] << "\n";
}

signed main() {
	clock_t start = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 191760