#include <bits/stdc++.h>

using namespace std;

const int N = 22;
const int MOD = 1e9 + 7;
int a[N][N];
int f[1 << N];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) cin >> a[i][j];
    f[0] = 1;
    for(int i = 1; i < (1 << n); i++) {
        int cur = __builtin_popcount(i) - 1;
        for(int j = 0; j < n; j++) if (((i >> j) & 1) && a[cur][j])
            f[i] = (f[i] + f[i ^ (1 << j)]) % MOD;
    }
    cout << f[(1 << n) - 1];
}
