#include <iostream>
#include <cstring>
using namespace std;
int n, a[21][21], mod = 1e9 + 7, dp[21][1 << 21];
int f(int p, int b) {
  if(p == n)
    return 1;
  if(dp[p][b] != -1)
    return dp[p][b];
  int sm = 0;
  for(int i = 0; i < n; ++i)
    if((~b & (1 << i)) && a[p][i])
      sm = (f(p + 1, b | (1 << i)) + sm) % mod;
  return dp[p][b] = sm;
  
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof dp);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      cin >> a[i][j];
  cout << f(0, 0);
}