Universal Cup Judging System

Universal Cup

时间限制: 2 s 内存限制: 1024 MB
统计

VegiCat 给你两个整数 $n$ 和 $m$。考虑满足如下条件的整数数组 $a_1, a_2, \ldots, a_n$:

$$ a_1 = 0, \qquad 0 \le a_{i+1} - a_i \le 1 \quad (1 \le i < n). $$

设 $s_i = a_1 + a_2 + \ldots + a_i$ 为 $a$ 的前缀和。VegiCat 还告诉了你 $m$ 个位置上的前缀和;也就是说,给定 $m$ 条形如 $s_{p_j} = v_j$($1 \le j \le m$)的限制。

problem_23594_7f47c20ec05f2c7c4e4e59a950db89af.png

求满足所有限制的数组数量,对 $998\,244\,353$ 取模。如果没有数组满足所有限制,则答案为 $0$。

输入格式

第一行包含一个整数 $T$($1 \le T \le 10^4$),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例的格式如下:

第一行包含两个整数 $n$ 和 $m$($1 \le n \le 100$,$0 \le m \le n$),分别表示数组的长度和前缀和限制的数量。

接下来 $m$ 行中的第 $j$ 行包含两个整数 $p_j$ 和 $v_j$($1 \le p_j \le n$,$0 \le v_j \le 10^9$)。这描述了一条限制:数组前 $p_j$ 个元素之和必须等于 $v_j$。

位置 $p_j$ 按严格递增顺序给出。

输出格式

对于每个测试用例,输出一个整数——合法数组的数量对 $998\,244\,353$ 取模的结果。

样例

输入格式 1

6
1 0
3 1
3 1
3 1
2 0
4 1
4 3
5 2
1 0
5 4
5 2
2 0
5 10

输出格式 1

1
1
2
2
2
0

说明

在没有任何前缀和限制的情况下,恰好有 $2^{n-1}$ 个这样的数组,因为 $n - 1$ 个相邻差分中的每一个都可以独立地取 $0$ 或 $1$。

在第二个测试用例中,唯一满足 $s_3 = 1$ 的数组是 $(0, 0, 1)$。

在第三个测试用例中,$s_2 = 0$ 强制 $a_2 = 0$,此后 $a_3$ 可以是 $0$ 或 $1$。

在第四个测试用例中,符合条件的数组为 $(0, 1, 1, 1)$ 和 $(0, 0, 1, 2)$。

在第五个测试用例中,满足 $s_5 = 4$ 的数组为 $(0, 0, 1, 1, 2)$ 和 $(0, 1, 1, 1, 1)$。

在第六个测试用例中,$s_2 = 0$ 强制 $a_1 = a_2 = 0$,因此 $s_5 \le 6$。限制 $s_5 = 10$ 是不可能满足的。

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.