Preparando MOJI

Connecting Vertices

4000ms 262144K

Description:

There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with each other (directly or indirectly).

But there are some restrictions. Firstly, some pairs of points cannot be connected directly and have to be connected undirectly. Secondly, the segments you draw must not intersect in any point apart from the marked points (that is, if any two segments intersect and their intersection is not a marked point, then the picture you have drawn is invalid).

How many ways are there to connect all vertices with n - 1 segments? Two ways are considered different iff there exist some pair of points such that a segment is drawn between them in the first way of connection, but it is not drawn between these points in the second one. Since the answer might be large, output it modulo 109 + 7.

Input:

The first line contains one number n (3 ≤ n ≤ 500) — the number of marked points.

Then n lines follow, each containing n elements. ai, j (j-th element of line i) is equal to 1 iff you can connect points i and j directly (otherwise ai, j = 0). It is guaranteed that for any pair of points ai, j = aj, i, and for any point ai, i = 0.

Output:

Print the number of ways to connect points modulo 109 + 7.

Sample Input:

3
0 0 1
0 0 1
1 1 0

Sample Output:

1

Sample Input:

4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

Sample Output:

12

Sample Input:

3
0 0 0
0 0 1
0 1 0

Sample Output:

0

Informação

Codeforces

Provedor Codeforces

Código CF888F

Tags

dpgraphs

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 09:20:29

Relacionados

Nada ainda