QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#2024. 平衡子集

Statistics

Farmer John 的牧场可以看作是一个巨大的二维网格,由坐标 $(i,j)$ 标记的方形“单元格”组成,其中 $1\le i\le N$,$1\le j\le N$ ($1\le N\le 150$)。其中一些单元格长有草。

如果一个非空单元格子集满足以下条件,则称其为“平衡的”:

  1. 子集中的所有单元格都长有草。
  2. 该子集是 4-连通的。换句话说,子集中的任意两个单元格之间都存在一条路径,使得路径上每两个相邻的单元格在水平或垂直方向上相邻。
  3. 如果单元格 $(x_1,y)$ 和 $(x_2,y)$ ($x_1\le x_2$) 属于该子集,则所有满足 $x_1\le x\le x_2$ 的单元格 $(x,y)$ 也属于该子集。
  4. 如果单元格 $(x,y_1)$ 和 $(x,y_2)$ ($y_1\le y_2$) 属于该子集,则所有满足 $y_1\le y\le y_2$ 的单元格 $(x,y)$ 也属于该子集。

计算平衡子集的数量,结果对 $10^9+7$ 取模。

输入格式

第一行包含 $N$。

接下来的 $N$ 行,每行包含一个长度为 $N$ 的字符串。从上往下第 $i$ 行的第 $j$ 个字符,如果该单元格 $(i,j)$ 长有草,则为 G,否则为 .。

输出格式

平衡子集的数量,结果对 $10^9+7$ 取模。

样例

输入格式 1

2
GG
GG

输出格式 1

13

说明

对于此测试用例,所有 4-连通的子集都是平衡的。

G.  .G  ..  ..  GG  .G  ..  G.  GG  .G  G.  GG  GG
.., .., G., .G, .., .G, GG, G., G., GG, GG, .G, GG

输入格式 2

4
GGGG
GGGG
GG.G
GGGG

输出格式 2

642

说明

以下是一个满足第二个条件(它是 4-连通的)但不满足第三个条件的子集示例:

GG..
.G..
GG..
....

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.