#P3977. [TJOI2015] 棋盘
[TJOI2015] 棋盘
Description
To improve his IQ, ZJY traveled to a new world. However, after traveling, ZJY unfortunately found that to open the door back to his original world, he must solve the puzzle drawn on the door. The puzzle is as follows:
There is an -row by -column board on which many special pieces can be placed. Each piece has an attack range of 3 rows and columns. The input provides a template of the attack range as a matrix. A piece is assumed to be at row , column of the template; positions it can attack are marked with , and positions it cannot attack are marked with . The input guarantees that the entry at row , column is . The password to open the door is the number of ways to place pieces on the board so that the pieces do not attack each other. Note that placing no pieces at all also counts as a valid arrangement. Since the number of arrangements may be large, and the password is a 32-bit binary number, ZJY only needs the number of arrangements modulo .
Note: indices start from , i.e., row refers to the middle row.
Input Format
The first line contains two integers and , representing the size of the board.
The second line contains two integers and , representing the size of the upcoming attack-range template and the piece’s position within the template.
The next three lines each contain numbers, describing the attack-range template. There is a space after each number.
Output Format
Output a single line with one integer, the number of valid arrangements modulo .
5 5
3 1
0 1 0
1 1 1
0 1 0
55447
Hint
Constraints
For 10% of the testdata, , .
For 50% of the testdata, , .
For 100% of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号