#include <bits/stdc++.h>
using namespace std;
const int N = 5e3;
const int mod = 1e9 + 7;
int f0[N][N], f1[N][N];
bool a[N][N];
int n;
void nhap() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
}
void lam() {
  for (int i = n - 1; i >= 0; --i) {
    f0[i][i] = 1;
    for (int j = i + 1; j < n; ++j) {
      for (int k = i + 1; k < j; ++k) {
        f0[i][j] =
            (f0[i][j] + 1ll * (f0[i][k] + f1[i][k]) * f1[k][j] % mod) % mod;
        while (f0[i][j] < 0) f0[i][j] += mod;
      }
      if (!a[i][j]) continue;
      for (int k = i; k < j; ++k) {
        f1[i][j] = (f1[i][j] + 1ll * (f0[i][k] + f1[i][k]) *
                                   (f0[k + 1][j] + f1[k + 1][j]) % mod) %
                   mod;
        while (f1[i][j] < 0) f1[i][j] += mod;
      }
    }
  }
  int ans = (f0[0][n - 1] + f1[0][n - 1]) % mod;
  while (ans < 0) ans += mod;
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  nhap();
  lam();
  return 0;
}
