#include<bits/stdc++.h>
using namespace std;
const int N=111;
int n,vis[N][N],now,sum[N];
char a[N][N];
void dfs(int x){sum[x]++;vis[now][x]=1;
	for(int i=1;i<=n;i++){if(a[x][i]=='1'&&!vis[now][i])
		dfs(i);
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)now=i,dfs(i);double ans=0;
	for(int i=1;i<=n;i++){
		ans+=1.0/sum[i];
	}printf("%.10lf",ans);
}
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
char mat[N][N];
int n;
int tout[N];
bool used[N];
int timer = 0;
int colored[N];
int c = 0;
set <int> g[N];
int _sz[N], _sz1[N];
void dfs(int v)
{
    used[v] = 1;
    for(int i = 0; i < n; i++)
    {
        if(mat[v][i] == '1' && !used[i])
        {
            dfs(i);
        }
    }
    tout[v] = timer++;
}
void dfs1(int v)
{
    colored[v] = c;
    used[v] = 1;
    _sz[c]++;
    for(int i = 0; i < n; i++)
    {
        if(mat[i][v] == '1' && !used[i])
        {
            dfs1(i);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < n; i++)
    {
        if(!used[i])
        {
            dfs(i);
        }
    }
    vector <pair <int, int> > mass;
    for(int i = 0; i < n; i++)
    {
        used[i] = 0;
        mass.push_back({tout[i], i});
    }
    sort(mass.begin(), mass.end());
    for(int i = mass.size() - 1; i >= 0; i--)
    {
        int v = mass[i].second;
        if(used[v])
        {
            continue;
        }
        dfs1(v);
        c++;
    }
    set <int> g1[N];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(mat[i][j] == '1')
            {
                g[colored[i]].insert(colored[j]);
                g1[colored[j]].insert(colored[i]);
            }
        }
    }
    double ans = 0;
    for(int i = 0; i < c; i++)
    {
        for(int j = 0; j < c; j++)
        {
            used[j] = 0;
        }
        queue <int> q;
        q.push(i);
        used[i] = 1;
        int _sz2 = 0;
        while(q.size() != 0)
        {
            int v = q.front();
            q.pop();
            if(v != i)
            {
                _sz2 += _sz[v];
            }
            set <int> :: iterator it;
            for(it = g1[v].begin(); it != g1[v].end(); it++)
            {
                if(!used[*it])
                {
                    used[*it] = 1;
                    q.push(*it);
                }
            }
        }
        double pw = 1;
        for(int j = 0; j <= n - _sz2 - _sz[i]; j++)
        {
            ans += pw * _sz[i] * 1.0 / (n - j);
            pw = pw * (n - j - _sz[i] - _sz2) * 1.0 / (n - j);
        }
    }
    cout << fixed << setprecision(10) << ans;
    return 0;
}
