#include <bits/stdc++.h>
using namespace std;
const long long N = 505;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  for (unsigned long long i = 0; i < a.size(); i++)
    os << a[i] << (i < a.size() - 1 ? ", " : "");
  os << ']';
  return os;
}
const long long mod = 1e9 + 7;
void add(long long &x, long long y) { x = (x + y) % mod; }
long long dp[N][N][2][2];
bool a[N][N];
long long cal(long long l, long long r, bool connect, bool conlr) {
  if (l + 1 == r && connect) return 1;
  if (l == r) return 1;
  long long &ret = dp[l][r][connect][conlr];
  if (ret != -1) return ret;
  ret = 0;
  if (!conlr && !connect && a[l][r]) {
    add(ret, cal(l, r, 1, 1));
  }
  for (long long j = (l + 1); j <= (r - 1); j++) {
    if (a[l][j]) add(ret, 1LL * cal(l, j, 1, 1) * cal(j, r, connect, 0) % mod);
  }
  if (connect) {
    for (long long j = (l + 1); j <= (r - 1); j++) {
      if (a[j][r]) add(ret, 1LL * cal(l + 1, j, 0, 0) * cal(j, r, 1, 1) % mod);
    }
  }
  return ret;
}
long long n;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (long long i = (1); i <= (n); i++) {
    for (long long j = (1); j <= (n); j++) cin >> a[i][j];
  }
  long long ans = 0;
  for (long long i = (2); i <= (n); i++) {
    if (a[1][i]) {
      add(ans, 1LL * cal(1, i, 1, 1) * cal(i, n, 0, 0) % mod);
    }
  }
  cout << ans << '\n';
}
