#P4262. [Code+#3] 白金元首与莫斯科

[Code+#3] 白金元首与莫斯科

Description

In an n×mn \times m grid, there is an army unit that needs resupply. Each cell in the area is either an empty cell or an obstacle. The air fleet needs to dispatch several transport planes to this area. Each transport plane can drop supplies to two adjacent (sharing a common edge) empty cells. To prevent unnecessary damage, a cell marked as empty can receive at most one drop.

Due to the weather, the exact location of the army unit cannot be determined. Therefore, for every empty cell, when the army unit is in that cell (treat it as an obstacle), the Führer wants to know the number of different schemes to drop any amount of supplies to the remaining empty cells using any number (possibly 00) of transport planes. Two schemes are different if and only if there exists a cell that is supplied in one scheme but not in the other, or there exist two supplied cells that are supplied by the same plane in one scheme but not so in the other. If you are still unsure, please refer to the explanation for Sample 1.

You need to write a program to compute these values.

Input Format

Line 1: two space-separated positive integers n,mn, m — the number of rows and columns of the grid region. Next nn lines: line ii contains mm space-separated integers Ai1,Ai2,,AimA_{i1}, A_{i2}, \ldots, A_{im}Aij=0A_{ij} = 0 means the cell in row ii, column jj is an empty cell; Aij=1A_{ij} = 1 means the cell is an obstacle.

Output Format

Output nn lines. Line ii contains mm space-separated integers Bi1,Bi2,,BimB_{i1}, B_{i2}, \ldots, B_{im} — if the cell in row ii, column jj is an empty cell, then BijB_{ij} is the number of schemes after turning that cell into an obstacle; otherwise Bij=0B_{ij} = 0. Each answer is taken modulo 109+710^9+7.

2 4
0 0 0 0
0 0 0 1
14 13 10 22
15 11 17 0

4 5
0 0 0 1 1
1 0 0 0 1
1 0 0 0 0
0 0 0 0 0

1882 827 1523 0 0
0 1189 791 1529 0
0 1106 979 823 1315
1810 899 1136 1075 1189

Hint

Explanation for Sample 1

Take the empty cell in row 22, column 11 as an example. After it is changed into an obstacle, the grid is as follows. Cells marked with o are empty, and cells marked with x are obstacles.

oooo
xoox

There are 1515 schemes as shown below. Different colors represent the drop positions of different transport planes.

Constraints

This problem uses bundled tests. The information for each test point is as follows: | Subtask ID | Points | nn | mm | | :----------: | :----------: | :----------: | :----------: | | 11 | 1010 | 2\le 2 | 17\le 17 | | 22 | 88 | 5\le 5 | 5\le 5 | | 33 | 66 | 9\le 9 | 9\le 9 | | 44 | 99 | 12\le 12 | 12\le 12 | | 55 | 1717 | 15\le 15 | 15\le 15 | | 66 | 1717 | 16\le 16 | 16\le 16 | | 77 | 3333 | 17\le 17 | 17\le 17 |

For all testdata, 1n,m171 \leq n, m \leq 17, Aij{0,1}A_{ij} \in \{0, 1\}.

Notes

Von allem Anfang an bin ich nur verraten und betrogen worden!

The statement does not fully agree with historical facts.

Credit: https://www.luogu.org/discuss/show?postid=35727

Translated by ChatGPT 5