#P8737. [蓝桥杯 2020 国 B] 质数行者

    ID: 9655 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020容斥原理蓝桥杯国赛

[蓝桥杯 2020 国 B] 质数行者

Background

Xiao Lan is playing a game called Prime Walker.

Problem Description

The game is played on a 3D grid of size n×m×wn \times m \times w. Rows are numbered from north to south as Row 11 to Row nn, columns are numbered from west to east as Column 11 to Column mm, and layers are numbered from bottom to top as Layer 11 to Layer ww.

Xiao Lan needs to control his character to move from Row 11, Column 11, Layer 11 to Row nn, Column mm, Layer ww. At each step, he may move east by a prime number of cells, move south by a prime number of cells, or move up by a prime number of cells. Each time he reaches a position, Xiao Lan’s character must stop there briefly.

There are two traps in the game, located at Row r1r_{1}, Column c1c_{1}, Layer h1h_{1} and Row r2r_{2}, Column c2c_{2}, Layer h2h_{2}. These trap positions may be crossed over, but the character is not allowed to stop on them. That is, Xiao Lan cannot make a move that lands exactly on a trap, but it is allowed for a move to pass over a trap in the middle.

Xiao Lan has been quite free recently, so he wants to finish the game in different ways. Two ways are considered different if the sets of positions where Xiao Lan stops briefly are different.

Please help Xiao Lan compute how many different ways there are in total.

Note: Please pay attention to the memory limit. If your program exceeds the memory limit during execution, it will receive zero points.

Input Format

The first line contains three integers n,m,wn, m, w, representing the size of the grid.

The second line contains 66 integers r1,c1,h1,r2,c2,h2r_{1}, c_{1}, h_{1}, r_{2}, c_{2}, h_{2}, representing the positions of the traps.

Output Format

Output one line containing one integer, representing the number of ways. The answer may be very large. Please output the remainder of the answer modulo 10000000071000000007 (i.e. 109+710^9+7).

5 6 1
3 4 1 1 2 1
11

Hint

Sample Explanation

Use (r,c,h)(r, c, h) to represent Row rr, Column cc, Layer hh. The possible ways are as follows:

  1. (1,1,1)(1,3,1)(1,6,1)(3,6,1)(5,6,1)(1,1,1)-(1,3,1)-(1,6,1)-(3,6,1)-(5,6,1).

  2. (1,1,1)(1,3,1)(3,3,1)(3,6,1)(5,6,1)(1,1,1)-(1,3,1)-(3,3,1)-(3,6,1)-(5,6,1).

  3. (1,1,1)(1,3,1)(3,3,1)(5,3,1)(5,6,1)(1,1,1)-(1,3,1)-(3,3,1)-(5,3,1)-(5,6,1).

  4. (1,1,1)(3,1,1)(3,3,1)(3,6,1)(5,6,1)(1,1,1)-(3,1,1)-(3,3,1)-(3,6,1)-(5,6,1).

  5. (1,1,1)(3,1,1)(3,3,1)(5,3,1)(5,6,1)(1,1,1)-(3,1,1)-(3,3,1)-(5,3,1)-(5,6,1).

  6. (1,1,1)(3,1,1)(5,1,1)(5,3,1)(5,6,1)(1,1,1)-(3,1,1)-(5,1,1)-(5,3,1)-(5,6,1).

  7. (1,1,1)(3,1,1)(5,1,1)(5,4,1)(5,6,1)(1,1,1)-(3,1,1)-(5,1,1)-(5,4,1)-(5,6,1).

  8. (1,1,1)(1,4,1)(1,6,1)(3,6,1)(5,6,1)(1,1,1)-(1,4,1)-(1,6,1)-(3,6,1)-(5,6,1).

  9. (1,1,1)(1,6,1)(3,6,1)(5,6,1)(1,1,1)-(1,6,1)-(3,6,1)-(5,6,1).

  10. (1,1,1)(3,1,1)(3,6,1)(5,6,1)(1,1,1)-(3,1,1)-(3,6,1)-(5,6,1).

  11. (1,1,1)(3,1,1)(5,1,1)(5,6,1)(1,1,1)-(3,1,1)-(5,1,1)-(5,6,1).

Constraints and Assumptions

For 30%30\% of the testdata, 1n,m,w501 \leq n, m, w \leq 50.

For 60%60\% of the testdata, 1n,m,w3001 \leq n, m, w \leq 300.

For all testdata, 1n,m,w10001 \leq n, m, w \leq 1000, 1r1,r2n1 \leq r_{1}, r_{2} \leq n, 1c1,c2m1 \leq c_{1}, c_{2} \leq m, 1h1,h2w1 \leq h_{1}, h_{2} \leq w. The traps are not at the start or the end, and the two traps are different.

Lanqiao Cup 2020 National Contest B Group, Problem J.

Translated by ChatGPT 5