#P3977. [TJOI2015] 棋盘

    ID: 2909 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推2015各省省选枚举,暴力状态压缩,状压进制天津

[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 nn-row by mm-column board on which many special pieces can be placed. Each piece has an attack range of 3 rows and pp columns. The input provides a template of the attack range as a 3×p3\times p matrix. A piece is assumed to be at row 11, column kk of the template; positions it can attack are marked with 11, and positions it cannot attack are marked with 00. The input guarantees that the entry at row 11, column kk is 11. 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 2322^{32}.

Note: indices start from 00, i.e., row 11 refers to the middle row.

Input Format

The first line contains two integers nn and mm, representing the size of the board.

The second line contains two integers pp and kk, representing the size of the upcoming attack-range template and the piece’s position within the template.

The next three lines each contain pp 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 2322^{32}.

5 5
3 1
0 1 0
1 1 1
0 1 0

55447

Hint

Constraints

For 10% of the testdata, 1n51 \leq n \leq 5, 1m51 \leq m \leq 5.

For 50% of the testdata, 1n10001 \leq n \leq 1000, 1m61 \leq m \leq 6.

For 100% of the testdata, 1n1061 \leq n \leq 10^{6}, 1m61 \leq m \leq 6.

Translated by ChatGPT 5