#include <bits/stdc++.h>
long long get() {
  long long x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
const long long M = 505, mo = 1e9 + 7;
long long n, dp[M][M][2];
bool a[M][M];
signed main() {
  n = get();
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) a[i][j] = get();
    dp[i][i][0] = 1;
  }
  for (long long len = 2; len <= n; ++len)
    for (long long l = 1; l + len - 1 <= n; ++l) {
      long long r = l + len - 1;
      if (a[l][r])
        for (long long 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]) % mo) %
              mo;
      for (long long k = l + 1; k < r; ++k)
        if (a[l][k])
          dp[l][r][1] =
              (dp[l][r][1] + dp[l][k][0] * (dp[k][r][0] + dp[k][r][1]) % mo) %
              mo;
    }
  printf("%d", (dp[1][n][0] + dp[1][n][1]) % mo);
  return 0;
}
