#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;

const int mod = 1000000007;

ll dp[1<<21] = {0};
int main() 
{
    int n;
    cin >> n;
    int a[n][n];
    rep(i,n)rep(j,n) cin >> a[i][j];

    dp[0] = 1;
    for (int b=1; b< 1<<21; b++) {
        int i = __builtin_popcount(b);
        rep(j,n) {
            if ((b>>j & 1) && (a[i-1][j] == 1)) {
                dp[b] += dp[b&~(1<<j)];
                dp[b] %= mod;
            }
        }
    }
    cout << dp[(1<<n) - 1] << endl;


    return 0;
}
