#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
int n, cnt;
vector<int> dp = {1};
vector<vector<int>> check;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    freopen("matching.inp", "r", stdin);
    freopen("matching.out", "w", stdout);
    cin >> n;
    dp.resize(1 << n);
    check.resize(n, vector<int>(n));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> check[i][j];
    for (int mask = 1; mask < (1 << n); mask++)
    {
        cnt = __builtin_popcount(mask);
        for (int j = 0; j < n; j++)
            if (mask >> j & 1 && check[cnt - 1][j])
                (dp[mask] += dp[mask ^ (1 << j)]) %= md;
    }
    cout << dp.back();
    return 0;
}