QOJ.ac

QOJ

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

#1912. Cave Paintings

統計

Bessie has become an artist and is creating paintings of caves! Her current work in progress is a grid of height $N$ such that each row of the grid contains exactly $M$ squares ($1\le N,M\le 1000$). Each square is either empty, filled with rock, or filled with water. Bessie has already painted the squares containing rock, including the entire border of the painting. She now wants to fill some empty squares with water such that if the painting were real, there would be no net motion of water. Define the height of a square in the $i$-th row from the top to be $N+1-i$. Bessie wants her painting to satisfy the following constraint:

Suppose that square $a$ is filled with water. Then if there exists a path from $a$ to square $b$ using only empty or water squares that are not higher than $a$ such that every two adjacent squares on the path share a side, then $b$ is also filled with water.

Find the number of different paintings Bessie can make modulo $10^9+7$. Bessie may fill any number of empty squares with water, including none or all.

Scoring

  • Test cases 1-5 satisfy $N,M\le 10.$
  • Test cases 6-15 satisfy no additional constraints.

Input Format

The first line contains two space-separated integers $N$ and $M$.

The next $N$ lines of input each contain $M$ characters. Each character is either '.' or '#', representing an empty square and a square filled with rock, respectively. The first and last row and first and last column only contain '#'.

Output Format

A single integer: the number of paintings satisfying the constraint modulo $10^9+7$.

Sample Input

4 9
#########
#...#...#
#.#...#.#
#########

Sample Output

9

If a square in the second row is filled with water, then all empty squares must be filled with water. Otherwise, assume that no such squares are filled with water. Then Bessie can choose to fill any subset of the three horizontally contiguous regions of empty squares in the third row. Thus, the number of paintings is equal to $1+2^3=9.$

Problem credits: Daniel Zhang

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.