QOJ.ac

QOJ

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

#16030. 洗牌

الإحصائيات

题目描述

小春最近很苦闷,面对书桌上的 $n$ 张牌,他决定给每张牌染色。目前小春只有 $3$ 种颜色:红色($r$),蓝色($b$),绿色($g$),他询问 Sun 有多少种染色方案,Sun 很快给出了答案,这让小春很吃惊。进一步,小春要求染出 $Sr$ 张红色,$Sb$ 张蓝色,$Sg$ 张绿色,他又询问 Sun 对此有多少种染色方案,Sun 稍微想了一会儿又给出了正确答案。

最后小春发明了 $m$ 种不同洗牌法,这时他又问 Sun 有多少种不同的染色方法,其中两种染色方法相同当且仅当两种染色方法中的一种可以通过任意的洗牌法(即可以使用多种洗牌法而且每种洗牌法可以使用多次)洗成另一种方法,Sun 发现这个问题有点难度,所以他决定把这个问题交给你,因为问题的答案可能很大,所以只要求出这个答案除 $p$ 之后的余数即可($p$ 为质数)。

输入格式

第 1 行有 5 个用空格隔开的整数,分别是 $Sr$、$Sb$、$Sg$、$m$ 和 $p$,$n=Sr+Sb+Sg$。接下来的 $m$ 行,每行描述一种洗牌法,每行有 $n$ 个用空格隔开的整数 $x_1,x_2,\ldots,x_n$,它恰好构成从 $1$ 到 $n$ 这 $n$ 个整数的一个排列,表示经过使用这种洗牌法一次后,第 $i$ 位的牌为原来第 $x_i$ 位的牌。输入数据保证任意多次洗牌都可用这 $m$ 种洗牌法中的一种代替,且对每种洗牌法,都存在一种洗牌法使得能回到原状态。其中,$m\le 60$,$p$ 为质数且 $m+1< p< 100$。

20% 的输入数据满足:$n=Sr+Sb+Sg\le 20$。

100% 的输入数据满足:$\max\{Sr,Sb,Sg\}\le 20$。

输出格式

仅包含一个整数,表示不同的染色方法总数除 $p$ 之后的余数。

样例数据

输入(input.txt)

1 1 1 2 7
2 3 1
3 1 2

输出(output.txt)

2

样例说明

共有 2 种本质上不同的染色方法 RGB 和 RBG。使用洗牌法 2 3 1 一次可得 GBR 和 BGR,使用洗牌法 3 1 2 一次可得 BRG 和 GRB。

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.