#P3160. [CQOI2012] 局部极小值

    ID: 2209 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2012重庆各省省选状态压缩,状压容斥

[CQOI2012] 局部极小值

Description

There is an nn by mm integer matrix in which each integer between 11 and n×mn \times m appears exactly once.

If a cell is smaller than all of its adjacent cells (adjacent means sharing a side or a vertex), we say this cell is a local minimum. Given the positions of all local minima, your task is to determine how many matrices are possible.

Output the answer modulo 12,345,67812{,}345{,}678.

Input Format

The first line contains two integers nn and mm, the number of rows and columns.

Each of the next nn lines contains mm characters. For each ii from 11 to nn, the (i+1) (i + 1) -th line’s jj-th character represents whether the cell at row ii and column jj is a local minimum. Each character is either X or ., where X denotes a local minimum and . denotes a non-local minimum.

Output Format

Output a single line containing the number of possible matrices modulo 12,345,67812{,}345{,}678.

3 2
X.
..
.X
60

Hint

  • Constraints
    • For 100%100\% of the testdata, 1n41 \le n \le 4, 1m71 \le m \le 7.

Translated by ChatGPT 5