#P8675. [蓝桥杯 2018 国 B] 搭积木
[蓝桥杯 2018 国 B] 搭积木
Description
Xiaoming is very interested in building blocks. All of his blocks are identical upright cubes.
When building, Xiaoming chooses blocks as the foundation, places them in a straight line on the table with no gaps, and calls this layer .
Then, Xiaoming can place layer , layer , , up to at most layer . Placing blocks must follow three rules:
Rule : Each block must be placed directly above some block, tightly adjacent to it, and aligned with the block in the layer below.
Rule : Blocks in the same layer must be placed continuously, with no gaps in between.
Rule : Blocks cannot be placed in positions that Xiaoming dislikes.
All positions that Xiaoming dislikes are marked on the blueprint. The blueprint has rows. From bottom to top, each row corresponds to layers to of the blocks. Each row has characters, which are either . or X, where X indicates a position that Xiaoming dislikes.
Now Xiaoming wants to know how many different ways there are to place the blocks. He asks you, as a Lanqiao Cup contestant, to help compute the answer.
Since the answer may be very large, you only need to output the result modulo .
Note: Placing nothing above the foundation is also considered one valid arrangement.
Input Format
The first line of the input contains two positive integers and , representing the size of the blueprint.
The next lines each contain characters describing the blueprint. Each character is either . or X.
Output Format
Output one integer, the answer modulo .
2 3
..X
.X.
4
Hint
Sample Explanation
Valid placements are as follows (where O means a block is placed):
1 2 3 4
..X ..X O.X ..X
.X. OX. OX. .XO
Constraints
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
Time limit: 1 second, 256 MB. Lanqiao Cup 2018, 9th National Finals.
Translated by ChatGPT 5
京公网安备 11011102002149号