#include <bits/stdc++.h>
using namespace std;
int flag[505][505], g[505][505], a[505][505], f[505][505], F[505][505];
int main() {
  int n;
  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++) f[i][i] = 1, F[i][i] = 0;
  for (int i = 1; i < n; i++) f[i][i + 1] = a[i][i + 1], F[i][i + 1] = 1;
  for (int len = 3; len <= n; len++)
    for (int l = 1; l <= n - len + 1; l++) {
      int r = l + len - 1;
      g[l][l] = 0;
      for (int i = l + 1; i <= r; i++) {
        if ((!a[l][i])) continue;
        if (flag[l][i]) {
          f[l][r] = ((long long)g[l][i] * f[i][r] + f[l][r]) % 1000000007;
          continue;
        }
        flag[l][i] = 1;
        g[l][i] = f[l + 1][i];
        for (int j = l + 1; j < i; j++)
          g[l][i] = ((long long)g[l][j] * F[j][i] + g[l][i]) % 1000000007;
        f[l][r] = ((long long)g[l][i] * f[i][r] + f[l][r]) % 1000000007;
      }
      for (int i = l; i < r; i++)
        F[l][r] = ((long long)f[l][i] * f[i + 1][r] + F[l][r]) % 1000000007;
    }
  printf("%d\n", f[1][n]);
  return 0;
}
