QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#4211. 爱丽丝与鲍勃

الإحصائيات

Alice 和 Bob 正在进行一场博弈,两人轮流操作,Alice 先手。 他们有一个有向无环图(DAG),其中每条边 $u \to v$ 都满足 $u < v$。 该 DAG 中的所有顶点都被染成两种颜色之一,且顶点上放置有棋子(一个顶点上可能包含多个棋子)。

在 Alice 的回合,她会选择一个包含至少一个棋子的白色顶点 $u$。然后,她选择一条从 $u$ 出发的边 $u \to v$,并将一个棋子从顶点 $u$ 移动到顶点 $v$。 在 Bob 的回合,他会选择一个包含至少一个棋子的黑色顶点 $u$。然后,他选择一条从 $u$ 出发的边 $u \to v$,并将一个棋子从顶点 $u$ 移动到顶点 $v$。 无法进行操作的人输掉比赛。

Alice 和 Bob 尚未决定棋子的初始配置,但他们已经决定在游戏开始时,每个顶点最多包含一个棋子。在所有 $2^n$ 种棋子放置方案中,计算有多少种方案使得 Alice 在双方均采取最优策略的情况下获胜?由于该数值可能很大,请输出其对 $998\,244\,353$ 取模的结果。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n \le 300, 0 \le m \le \frac{n(n-1)}{2}$),表示图中的顶点数和边数。 第二行包含一个长度为 $n$ 的字符串。如果第 $i$ 个字符为 ‘W’,则该顶点为白色。否则,字符为 ‘B’,表示该顶点为黑色。 接下来的 $m$ 行,每行包含两个顶点 $u, v$ ($1 \le u < v \le n$),表示一条边 $u \to v$。 保证该 DAG 不包含重边。

输出格式

输出一个整数:在每个顶点最多放置一个棋子的所有方案中,使得 Alice 获胜的方案数,对 $998\,244\,353$ 取模。

样例

输入格式 1

5 4
WWWWW
1 2
2 3
3 4
4 5

输出格式 1

30

说明

在第一个样例中,Alice 在所有她至少能进行一次操作的情况下都会获胜(因为 Bob 永远无法移动),因此答案是 $2^5 - 2$。

输入格式 2

5 4
BWBWB
1 2
2 3
3 4
4 5

输出格式 2

24

输入格式 3

9 14
BWWBBBWWW
1 2
1 9
2 3
2 4
2 6
2 8
3 4
3 7
4 7
4 8
5 7
5 9
6 9
7 8

输出格式 3

300

输入格式 4

10 15
BWBWBBWWBW
1 2
1 5
1 10
2 6
2 8
3 6
3 7
4 10
5 6
5 7
5 8
6 8
6 9
7 10
8 9

输出格式 4

228

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.