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

template <long long mod>
class Mod
{
    long long value;
    void set_value(const long long x)
    {
        this->value = x % mod;
    }

public:
    Mod()
    {
        set_value(0ll);
    }

    template <typename T>
    Mod(T x = 0)
    {
        set_value((long long)x);
    }

    friend istream &operator>>(istream &is, Mod &x)
    {
        long long tmp;
        is >> tmp;
        x.set_value(tmp);
        return is;
    }

    friend ostream &operator<<(ostream &os, const Mod &x)
    {
        os << x.value;
        return os;
    }

    operator long long() const
    {
        return this->value;
    }

    template <typename T>
    bool operator<(const T x)
    {
        return this->value < (long long)x;
    }

    template <typename T>
    bool operator<=(const T x)
    {
        return this->value <= (long long)x;
    }

    template <typename T>
    bool operator>(const T x)
    {
        return this->value > (long long)x;
    }

    template <typename T>
    bool operator>=(const T x)
    {
        return this->value >= (long long)x;
    }

    template <typename T>
    bool operator==(const T x)
    {
        return this->value == (long long)x;
    }

    template <typename T>
    Mod &operator=(const T x)
    {
        set_value((long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator&=(const T x)
    {
        set_value(this->value & (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator|=(const T x)
    {
        set_value(this->value | (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator^=(const T x)
    {
        set_value(this->value ^ (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator<<=(const T x)
    {
        set_value(this->value << (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator>>=(const T x)
    {
        set_value(this->value >> (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator+=(const T x)
    {
        set_value(this->value + (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator-=(const T x)
    {
        set_value(this->value - (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator*=(const T x)
    {
        set_value(this->value * (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator/=(const T x)
    {
        long long a = (long long)x;
        long long b = mod;
        long long u = 1;
        long long v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= mod;
        if (u < 0)
            u += mod;
        *this *= Mod(u);
        return *this;
    }

    template <typename T>
    Mod operator&(const T x) const
    {
        return Mod(*this) &= x;
    }

    template <typename T>
    Mod operator|(const T x) const
    {
        return Mod(*this) |= x;
    }

    template <typename T>
    Mod operator^(const T x) const
    {
        return Mod(*this) ^= x;
    }

    template <typename T>
    Mod operator<<(const T x) const
    {
        return Mod(*this) <<= x;
    }

    template <typename T>
    Mod operator>>(const T x) const
    {
        return Mod(*this) >>= x;
    }

    template <typename T>
    Mod operator+(const T x) const
    {
        return Mod(*this) += x;
    }

    template <typename T>
    Mod operator-(const T x) const
    {
        return Mod(*this) -= x;
    }

    template <typename T>
    Mod operator*(const T x) const
    {
        return Mod(*this) *= x;
    }

    template <typename T>
    Mod operator/(const T x) const
    {
        return Mod(*this) /= x;
    }

    Mod &operator++()
    {
        *this += 1;
        return *this;
    }

    Mod &operator--()
    {
        *this -= 1;
        return *this;
    }

    Mod operator++(auto)
    {
        Mod ret(*this);
        ++*this;
        return ret;
    }

    Mod operator--(auto)
    {
        Mod ret(*this);
        --*this;
        return ret;
    }
};

template <long long mod>
void dfs(vector<vector<Mod<mod>>> &dp, vector<vector<bool>> &a, int n, int i, int j)
{
    if (i == ((1 << n) - 1) && j == ((1 << n) - 1))
    {
        return;
    }
    for (int from = 0; from < n; from++)
    {
        int next_i = i + (1 << from);
        if ((i >> from) & 0x1)
        {
            continue;
        }
        for (int to = 0; to < n; to++)
        {
            int next_j = j + (1 << to);
            if ((j << to) & 0x1)
            {
                continue;
            }
            if (a[next_i][next_j])
            {

                dp[next_i][next_j] += dp[i][j];
                dfs(dp, a, n, next_i, next_j);
            }
        }
    }
}

int main()
{
    const long long MOD = 1'000'000'007;

    int N;
    cin >> N;

    vector<vector<bool>> a(N + 1, vector<bool>(N + 1, false));
    int tmp;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            cin >> tmp;
            a[i][j] = tmp == 1;
        }
    }

    vector<vector<Mod<MOD>>> dp(N + 1, vector<Mod<MOD>>((1 << N), 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j < (1 << N); j++)
        {
            bitset<32> b(j << 1);
            if (b.count() != i)
            {
                continue;
            }
            for (int k = 1; k <= N; k++)
            {
                if (!b[k])
                {
                    continue;
                }
                if (a[i][k])
                {
                    dp[i][j] += dp[i - 1][((j << 1) - (1 << k)) >> 1];
                }
            }
        }
    }
    cout << dp.back().back() << endl;
}


Measured memory_bytes: 377216