'use strict'

var mod = 1e9 + 7

function solve(N, A) {
  let dp = new Array(N+1).fill(0).map(e => new Array(Math.pow(2, N)).fill(0))
  dp[0][0] = 1
  dp[0][Math.pow(2, N) - 1] = 1

  for (var i = 1; i <= N; i++) {
    for (var j = 0; j < Math.pow(2, N); j++) {
      if (i === N && j > 0) {
        break
      }
      for (var k = 0; k < N; k++) {
        if ((j & (1 << k)) === 0 && A[i-1][k] === 1) {
          dp[i][j] = (dp[i][j] + dp[i-1][j | (1 << k)]) % mod
        }
      }
    }
  }
  return dp[N][0]
}

function main(input) {
  var lines = input.split("\n")
  var N = parseInt(lines[0])
  var A = lines.slice(1).map(l => l.split(' ').map(e => parseInt(e)))
  var ans = solve(N, A)
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
