QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#12884. 宾果!

Statistics

新学年开始了!霍格沃茨的每个人都对学习新事物感到非常兴奋。哈利·波特正在参加一门关于咒语的新课程,在那里他正在学习如何阅读人们的思想并确定他们的下一步行动。哈利打算和赫敏玩一个游戏,他想尝试使用新咒语来赢得比赛。

哈利和赫敏准备玩宾果游戏!每个玩家都将拥有一块 $5 \times 5$ 的棋盘,上面包含 $1$ 到 $25$ 的数字(每个数字恰好出现一次)。游戏轮流进行,哈利先手。每个玩家大声说出一个数字(该数字尚未被标记),双方都在各自的棋盘上标记该数字。第一个在棋盘上填满 $5$ 个完整的行、列或对角线的玩家大喊“宾果!”并赢得比赛。如果他们同时大喊,则视为平局,没有人获胜。

由于哈利能读懂赫敏的心思,他可以看到她的棋盘配置,并知道她接下来要喊出的数字序列(当然,她会跳过哈利已经喊出的数字!)。罗恩不能让他们独自玩耍!他问了哈利一个数学问题。你有多少种方法可以赢得这场比赛?如果两种方法在第 $i$ 回合喊出的数字不同,则视为不同。由于这个数字可能很大,请将其对 $1,000,000,007$ 取模。

输入格式

你的程序将在一个或多个测试用例上进行测试。输入的第一行是一个整数 $T$,表示测试用例的数量($1 \le T \le 50$),随后是 $T$ 个测试用例。

每个测试用例将分多行呈现。前 $5$ 行代表哈利的棋盘,每行包含 $5$ 个由空格分隔的整数。接下来的 $5$ 行以相同的格式代表赫敏的棋盘。最后一行将包含一个由 $1$ 到 $25$ 的数字组成的排列,由空格分隔,代表赫敏喊出的数字顺序。保证 $1$ 到 $25$ 的每个数字在哈利的棋盘、赫敏的棋盘以及赫敏喊出的数字中都只出现一次。

输出格式

对于每个测试用例,输出一行,包含哈利赢得比赛的方法数,结果对 $1,000,000,007$ 取模。

样例

输入 1

2
16 22 11 21 15
18 24 13 14 25
8 9 7 2 4
3 19 23 17 12
20 5 1 6 10
24 17 21 8 10
15 2 16 25 7
13 12 3 14 9
19 1 6 4 20
23 22 5 11 18
15 18 16 17 13 19 1 24 23 21 20 4 9
11 2 12 22 7 8 3 25 14 5 6 10
20 11 22 2 19
17 25 23 14 13
10 8 6 21 18
12 1 5 24 16
7 4 15 3 9
18 10 20 12 11
1 23 13 8 15
6 7 9 19 24
25 21 3 17 2
14 22 4 16 5
9 13 6 24 5 21 10 22 25 11 23 15 17 8
19 2 20 18 7 4 16 12 1 3 14

输出 1

775283109
200384431

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.