#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

template <typename T >
void print_vec_2d(vector<vector<T>> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << "[ ";
		for (int j=0;j<x[i].size();j++) {
			cout << x[i][j];
			if (j != x[i].size()-1) cout << ", ";
			else {
				cout << " ]";
				if (!((i == x.size()-1) && (j == x[i].size()-1))) {
					cout << "," << endl;
				}
			}
		}
	}
	cout << " ]" << endl;
}

int N;
vector<string> S;

int bfs(int i) {
	queue<int> q;
	q.push(i);
	vector<bool> visited(N, false);
	while (!q.empty()) {
		int ind = q.front();
		q.pop();
		visited[ind] = true;
		for (int j=0;j<N;j++) {
			if (visited[j]) continue;
			if (S[j][ind] == '1') {
				q.push(j);
			}
		}
	}
	int ret = 0;
	for (int j=0;j<N;j++) {
		if (visited[j]) ret++;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	S = vector<string>(N);
	for (int i=0;i<N;i++) {
		cin >> S[i];
	}

	double ans = 0;
	for (int i=0;i<N;i++) {
		ans += (double)1/bfs(i);
	}
	// cout << ans << "\n";
	cout << fixed << setprecision(12) << ans << "\n";
}
/**
*    author:  
*    created: 15.11.2020 00:24:55
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 1001001001;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
typedef vector<int> vi;
typedef vector<vi> vvi;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}
template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int> (n,0));
  rep(i,n){
    rep(j,n){
      char c;
      cin >> c;
      if(c == '1') a[i][j] = 1;
    }
  }
  rep(i,n) a[i][i] = 1;
  rep(k,n)rep(i,n)rep(j,n) a[i][j] |= a[i][k] & a[k][j];
  double ans = 0;
  rep(i,n){
    int cnt = 0;
    rep(j,n) cnt += a[j][i];
    ans += double(1)/double(cnt);
  }
  cout << fixed << setprecision(10);
  cout << ans << "\n";
  return 0;
}