#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int M = 1e9 + 7;
bool a[N][N];
long long dp[N][N][2];
long long calc(int l, int r, bool t) {
  if (dp[l][r][t] >= 0) return dp[l][r][t];
  if (r - l <= 1) return 1;
  long long ans = 0;
  if (t == 0) {
    for (int i = l + 1; i < r; i++) {
      if (a[i][r] == 0) continue;
      long long inc = calc(l, i, 0) * calc(i, r, 1);
      ans = (ans + inc) % M;
    }
  } else {
    for (int i = l + 1; i < r; i++) {
      if (a[l][i] == 0) continue;
      long long inc = calc(l, i, 1) * calc(i, r, 1);
      ans = (ans + inc) % M;
    }
    ans = (ans + calc(l, r, 0)) % M;
  }
  return dp[l][r][t] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i <= n; i++) a[i][n] = a[n][i] = a[i][0];
  memset(dp, -1, sizeof dp);
  cout << calc(0, n, 0) % M << endl;
}
