#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll n;
  cin >> n;
  mat a(n,vec(n));
  for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) cin >> a[i][j];
  vec dp(1<<n);
  dp[0]=1;
  for(ll s=1;s<(1<<n);s++) {
    bitset<22> bit(s);
    ll i=bit.count();
    for(ll j=0;j<n;j++) {
      if(bit.test(j)&&a[i-1][j]) {
        (dp[s]+=dp[s^(1<<j)])%=mod;
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
}