Graph Coloring 2

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are given an undirected graph with nn vertices numbered 00 through n1n - 1. Obviously, the set of vertices have 2n12^n - 1 non-empty subsets. For a non-empty subset SS, a proper coloring of SS is a way to assign each vertex in SS a color, so that no two vertices in SS with the same color are directly connected by an edge. Assume we used kk different kinds of colors in a proper coloring. The chromatic number of subset SS is the minimum possible kk among all the proper colorings of SS.

Now your task is to compute the chromatic number of every non-empty subset of nn vertices.

입력

The first line contains an integer TT. Then TT test cases follow.

The first line of each test case contains an integer nn. Each of then next nn lines contains a string consisting of '0' and '1'. For 0in10 \le i \le n - 1 and 0jn10 \le j \le n - 1, if the jj-th character of the ii-th line is '1', then vertices ii and jj are directly connected by an edge, otherwise they are not directly connected.

The ii-th character of the ii-th line is always '0'. The ii-th character of the jj-th line is always the same as the jj-th character of the ii-th line.

For all test cases, 1n181 \le n \le 18. There are no more than 100100 test cases with 1n101 \le n \le 10, no more than 33 test cases with 11n1511 \le n \le 15, and no more than 22 test cases with 16n1816 \le n \le 18.

출력

For each test case, print an integer on a separate line. This integer is determined as follows: We define the identity number of subset SS as id(S)=_vS2v\mathit{id} (S) = \sum\_{v \in S} 2^v. Let the chromatic number of SS be f_id(S)f\_{\mathit{id} (S)}. You need to output (_id(S)=12n1f_id(S)233id(S))mod232.\left(\sum\limits\_{\mathit{id} (S) = 1}^{2^n - 1} f\_{\mathit{id} (S)} \cdot 233^{\mathit{id} (S)}\right) \bmod 2^{32}\text{.}

힌트

For the first test case, ans\[1..15]=1,1,2,1,2,2,3,1,1,1,2,2,2,2,3ans\[1..15] = \\{1, 1, 2, 1, 2, 2, 3, 1, 1, 1, 2, 2, 2, 2, 3\\}.