#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxb=21,mod=1e9+7;
ll n,ady[maxb][maxb],dp[1<<maxb];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,0,n)
        rep(j,0,n)
            cin>>ady[i][j];
    dp[(1<<n)-1]=1;
    per(msk,0,(1<<n)-1) {
        ll i=__builtin_popcount(msk);
        rep(j,0,n) if(~msk&1<<j && ady[i][j])
            dp[msk]=(dp[msk]+dp[msk|1<<j])%mod;
    }
    cout<<dp[0]<<"\n";
}
