#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;
using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
const ll mod=1e9+7;
using modint = ModInt< mod >;


int N;
int A[22][22];
void input(){
  fast_io();
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> A[i][j];
  
}

// modint dp[30][1<<22];
// bool used[30][1<<22];
vector<vector<modint> > dp;
vector<vector<bool> > used;

modint rec(int i=0, ll bit=0){
  modint ret=0;
  if(used[i][bit]) return dp[i][bit];
  used[i][bit] = true;
  if(i==N) return dp[i][bit] = 1;
  for (int j = 0; j < N; j++)
  {
    if((bit>>j)&1) continue;
    if(A[i][j]) ret += rec(i+1,bit|(1<<j));
  }
  return dp[i][bit] = ret;  
}

int solve(){
  dp.assign(N+1,vector<modint>(1<<N,0));
  used.assign(N+1,vector<bool>(1<<N,false));
  cout << rec() << endl;
  return 0;
}

int main()
{
  // maketestcase(400);
  input();
  solve();
  return 0;
}


int TLEsolve(){
  // memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= N; i++)
  {
    for (ll bit = 0; bit < 1<<N; bit++)
    {
      for (int j = 0; j < N; j++)
      {
        if((bit>>j)&1) continue;
        if(A[i-1][j]) dp[i][bit|(1<<j)] += dp[i-1][bit];
      }
    }
  }
  cout << dp[N][(1<<N)-1] << endl;
  
  return 0;
}


Measured memory_bytes: 188800