#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 510;
int dp[N][N][2];
int a[N][N];
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++) {
    dp[i][i][1] = 1;
  }
  for (int len = 2; len <= n; len++) {
    for (int i = 1; i <= n - len + 1; i++) {
      int j = (i + len - 1);
      if (a[i][j]) {
        for (int k = i; k < j; k++) {
          dp[i][j][1] =
              (dp[i][j][1] + 1LL * (dp[i][k][0] + dp[i][k][1]) *
                                 (dp[k + 1][j][0] + dp[k + 1][j][1])) %
              mod;
        }
      }
      for (int k = i + 1; k < j; k++) {
        if (a[i][k]) {
          dp[i][j][0] =
              (dp[i][j][0] + 1LL * dp[i][k][1] * (dp[k][j][0] + dp[k][j][1])) %
              mod;
        }
      }
    }
  }
  cout << (dp[1][n][0] + dp[1][n][1]) % mod << endl;
  return 0;
}
