P24903 [AtCoder] Erasing Vertices
提高-
题目描述

Problem Statement

We have a directed graph with N vertices numbered 1 to N.
N strings of length N each$, S_1,S_2,\ldots,S_N,$ represent the edges in the graph.
Specifically, S_{i,j} is 1 if there is an edge from Vertex i to Vertex j, and 0 otherwise.
The graph has no self-loops and no multi-edges.
Until the graph becomes empty, AtCobear will repeat the following operation:

  • Choose one (unerased) vertex uniformly at random (independently from the previous choices).
    Then, erase that vertex and all vertices that are reachable from the chosen vertex by traversing some edges.
    Erasing a vertex will also erase the edges incident to it.

Find the expected value of the number of times the operation is done.

Input

Input is given from Standard Input in the following format:
N
S_1
S_2
$\vdots$
S_N

Output

Print the expected value of the number of times the operation is done.
Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-9}.

Constraints

  • $1 \leq N \leq 100$
  • S_i is a string of length N consisting of 0 and 1.
  • S_{i,i}=0

Sample Input 1

3
010
001
010

Sample Output 1

1.66666666666666666667

We have the following three scenarios happening with equal probability:

  • Choose Vertex 1 in the first operation, erasing Vertex 1, 2, and 3.
    The graph is now empty, so we are done.

  • Choose Vertex 2 in the first operation, erasing Vertex 2 and 3.
    Then, choose Vertex 1 in the second operation, erasing Vertex 1.
    The graph is now empty, so we are done.

  • Choose Vertex 3 in the first operation, erasing Vertex 2 and 3.
    Then, choose Vertex 1 in the second operation, erasing Vertex 1.
    The graph is now empty, so we are done.

Thus, the expected value of the number of times the operation is done is (1+2+2)/3=5/3.

Sample Input 2

3
000
000
000

Sample Output 2

3.00000000000000000000

There will always be three operations.

Sample Input 3

3
011
101
110

Sample Output 3

1.00000000000000000000

There will always be one operation.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 010 001 010
样例输出
1.66666666666666666667