#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 510, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long dp[MAXN][MAXN][2];
bool A[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> A[i][j];
  for (int i = 1; i <= n; i++) dp[i][i][0] = dp[i][i][1] = 1;
  for (int r = 1; r <= n; r++)
    for (int l = r - 1; l; l--) {
      if (r - l == 1) {
        dp[l][r][0] = A[l][r];
        dp[l][r][1] = 1;
        continue;
      }
      for (int i = 1; i <= n; i++)
        if (A[r][i] && l < i) {
          dp[l][r][0] += dp[l][i][0] * dp[i][r][1] % mod;
          dp[l][r][1] += dp[l][i][1] * dp[i][r][1] % mod;
        }
      dp[l][r][1] += dp[l][r - 1][0];
      if (A[l][r]) dp[l][r][0] += dp[l][r][1];
      dp[l][r][0] %= mod;
      dp[l][r][1] %= mod;
    }
  cout << dp[1][n][0] << '\n';
  return 0;
}
