#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500 + 5;
const int Mod = 1e9 + 7;
long long n, a[MAXN][MAXN], dp[MAXN][MAXN][2];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%lld", &a[i][j]);
  for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
  for (int i = 2; i <= n; i++) {
    for (int l = 1, r = i; r <= n; l++, r++) {
      if (a[l][r] == 1)
        for (int k = l; k < r; k++)
          dp[l][r][0] =
              (dp[l][r][0] + (dp[l][k][0] + dp[l][k][1]) *
                                 (dp[k + 1][r][0] + dp[k + 1][r][1]) % Mod) %
              Mod;
      for (int k = l + 1; k <= r - 1; k++)
        if (a[l][k] == 1)
          dp[l][r][1] =
              (dp[l][r][1] + dp[l][k][0] * (dp[k][r][0] + dp[k][r][1]) % Mod) %
              Mod;
    }
  }
  printf("%lld\n", (dp[1][n][0] + dp[1][n][1]) % Mod);
  return 0;
}
