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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> A(n, vector<int>(n));
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> A[i][j];
    int p = int(1e9) + 7;

    vector<int> DP(1 << n, 0);
    DP[0] = 1;

    for (int S = 1; S < 1 << n; S++){
        int i = __builtin_popcount(S) - 1;
        int s = 0;
        for (int j = 0; j < n; j++)
            if (A[i][j]) s = (s + DP[S & ~(1 << j)]) % p;
        DP[S] = s;
    }

    cout << DP[(1 << n) - 1] << endl;
}