#include <bits/stdc++.h>
const int N = 505, mu = 1e9 + 7;
void reduce(int &x) { x += x >> 31 & mu; }
int a[N][N], dp[N][N][2], n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
  for (int i = 1; i < n; i++)
    if (a[i][i + 1]) dp[i][i + 1][1] = 1;
  for (int len = 2; len < n; len++)
    for (int l = 1, r = l + len; r <= n; l++, r++) {
      if (a[l][r])
        for (int k = l; k < r; k++)
          reduce(dp[l][r][1] += 1ll * (dp[l][k][0] + dp[l][k][1]) *
                                    (dp[k + 1][r][0] + dp[k + 1][r][1]) % mu -
                                mu);
      for (int k = l + 1; k < r; k++)
        reduce(dp[l][r][0] +=
               1ll * dp[l][k][1] * (dp[k][r][0] + dp[k][r][1]) % mu - mu);
    }
  printf("%d\n", (dp[1][n][0] + dp[1][n][1]) % mu);
}
