#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x;
}
int n, a[505][505];
int dp[505][505][2];
int dfs(int l, int r, int k) {
  if (~dp[l][r][k]) return dp[l][r][k];
  if (l == r && !k) return 1;
  int& res = dp[l][r][k] = 0;
  if (!k) {
    if (a[l][r])
      for (register int i = (l); i <= (r - 1); ++i)
        res = res + 1ll * (dfs(l, i, 0) + dfs(l, i, 1)) *
                        (dfs(i + 1, r, 0) + dfs(i + 1, r, 1)) % 1000000007,
        res %= 1000000007;
  }
  if (k) {
    for (register int i = (l + 1); i <= (r - 1); ++i)
      if (a[l][i])
        res = (res + 1ll * dfs(l, i, 0) * (dfs(i, r, 0) + dfs(i, r, 1)) %
                         1000000007) %
              1000000007;
  }
  return res;
}
signed main() {
  n = read();
  for (register int i = (1); i <= (n); ++i)
    for (register int j = (1); j <= (n); ++j) a[i][j] = read();
  memset(dp, -1, sizeof dp);
  cout << (dfs(1, n, 0) + dfs(1, n, 1)) % 1000000007;
  return 0;
}
