#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=1;i<=(n);++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define RI(x) scanf("%d",&x)
#define RII(x,y) scanf("%d%d",&x,&y)
int n; 
char con[105][105];
vector<int> R[105];
int up[105];
bool vis[105];
inline void dfs(int u,int rt){
	++up[rt];vis[u]=1;
	for (int i=0;i<R[u].size();++i) if (!vis[R[u][i]]) dfs(R[u][i],rt);
}
double ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n) cin>>con[i]+1;
	REP(i,n) REP(j,n) if (con[i][j]=='1') R[j].pb(i);
	REP(i,n){
		memset(vis,0,sizeof(vis));
		dfs(i,i);//--up[i];
		//cerr<<i<<' '<<up[i]<<endl;
		ans+=double(1.0)/up[i];
	}
	printf("%0.10lf",ans);
	
	return 0;
}
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[1200010];
char *ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
char tc[200002], *di = tc + 100000, *di2 = tc + 200000;
const char d[2] = "0";

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

	rep(i, 100000) tc[i] = '0';
	rep(i, 100000) di[i] = '1';
	di2[0] = '0';
	di2[1] = '\n';
	fread(cn, 1, 1200010, stdin);
	int T = getint();
	//while ((ct = *ci++) >= '0') T = T * 10 + ct - '0';

	rep(t, T) {
		int N = getint();
		//while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
		fwrite(di - N, 1, N, stdout);
		fwrite(di2 - N, 1, N + 2, stdout);
		ci += 6 * N + 3;
	}

	Would you please return 0;
}