#P5933. [清华集训 2012] 串珠子

    ID: 4898 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2012状态压缩,状压清华集训

[清华集训 2012] 串珠子

Description

Mingming has nn very beautiful beads and several strings of different colors. Now Mingming wants to use strings to connect all the beads into a whole.

It is known that all beads are distinct and are numbered from 11 to nn. For bead ii and bead jj, you may choose not to connect them, or choose one string from ci,jc_{i,j} strings of different colors to connect them. If we view beads as vertices and strings as edges, connecting all beads into a whole means that all vertices form a connected graph. In particular, a bead cannot be connected to itself.

Mingming wants to know how many different ways there are to connect all the beads into a whole. Since the answer may be very large, output the result modulo 10000000071000000007.

Input Format

The first line contains a positive integer nn, the number of beads. The next nn lines each contain nn non-negative integers separated by spaces. In these nn lines, the jj-th number in the ii-th line is ci,jc_{i,j}.

Output Format

Output one integer in one line, the number of connection schemes modulo 10000000071000000007.

3
0 2 3
2 0 4
3 4 0

50

Hint

Sample Explanation

Depending on whether each pair of beads is connected, there are the following four types of connection methods.

Picture

For each type, the number of methods it contains is the product of the ci,jc_{i,j} values of the corresponding included edges.

Graph (1) has 2×3×4=242\times3\times4=24 methods, graph (2) has 2×4=82\times4=8 methods, graph (3) has 2×3=62\times3=6 methods, and graph (4) has 3×4=123\times4=12 methods, for a total of 5050 methods.

Constraints

For 100%100\% of the testdata, nn is a positive integer, and all ci,jc_{i,j} are non-negative integers not exceeding 10000000071000000007. It is guaranteed that ci,j=cj,ic_{i,j}=c_{j,i}. The values of nn for each test group are as follows.

ID 1 2 3 4 5 6 7 8 9 10
nn 88 99 1010 1111 1212 1313 1414 1515 1616

Translated by ChatGPT 5