QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100

#13101. 神秘矩阵

统计

Eleanor 喜欢括号。她最喜欢合法的括号序列。一个由 '(' 和 ')' 字符组成的字符串 $w$ 被称为合法括号序列,如果满足以下两个条件:

  • $w$ 中左括号和右括号的数量相等;
  • $w$ 的任意前缀中,左括号的数量大于或等于右括号的数量。

例如,“(())()” 或 “()()()” 是合法括号序列,而 “((((” 或 “())(” 则不是。

Eleanor 想要将合法括号序列的概念推广到矩阵,但她第一次尝试要求每一行和每一列都必须是合法括号序列,结果失败了:显然不存在这样的矩阵。

她的第二次尝试是定义所谓的“神秘括号矩阵”(enigmatic bracket matrix)。

如果一个由 '(' 和 ')' 字符组成的矩阵的每一行都是某个合法括号序列的循环移位,且每一列也都是某个合法括号序列的循环移位,则称该矩阵为神秘矩阵。

如果存在(可能为空的)字符串 $u$ 和 $v$,使得 $x = uv$ 且 $y = vu$,则称字符串 $x$ 是字符串 $y$ 的循环移位。

例如,下图展示了一个神秘的 $4 \times 4$ 矩阵:

(())
()()
)()(
))((

现在 Eleanor 想要计算不同的 $h \times w$ 神秘矩阵的数量。请帮帮她!答案需要对 $998\,244\,353$ 取模。

输入包含多个测试用例。每个测试用例包含一行,包含两个整数 $h$ 和 $w$ ($2 \le h, w \le 16$,$h$ 和 $w$ 均为偶数)。最后一个测试用例后跟一行包含两个零的行,该行不应被处理。

对于每个测试用例,输出一个整数:神秘 $h \times w$ 矩阵的数量,对 $998\,244\,353$ 取模。

样例

输入格式 1

4 4
0 0

输出格式 1

90

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.