#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define endl '\n'

using ull = unsigned long int;
using ll = long long;

template <class Key, class Val>
using hmap = gp_hash_table<Key, Val>;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    const int precision = 13;
    cout.precision(precision);
    cout.setf(ios_base::fixed);

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n, 0));
    for (auto& v : a) for (int& i : v) cin >> i;

    const ll mod = 1e9 + 7;
    vector<vector<ll>> dp(n, vector<ll>(1<<n, 0));
    for (int i = 0; i < n; ++i) {
      dp[0][1<<i] = a[0][i];
    }

    for (int i = 1; i < n; ++i) {
      for (int mask = 1; mask < (1<<n); ++mask) {
        for (int j = 0; j < n; ++j) {
          if (!(mask & (1<<j)) or a[i][j] == 0) continue;
          int from = mask^(1<<j);
          dp[i][mask] += dp[i-1][from];
          if (dp[i][mask] > mod) dp[i][mask] -= mod;
        }
      }
    }

    cout << dp[n-1][(1<<n) -1] << endl;

    return 0;
}
