311164: CF1943D1. Counting Is Fun (Easy Version)
Description
This is the easy version of the problem. The only difference between the two versions is the constraint on $n$. You can make hacks only if both versions of the problem are solved.
An array $b$ of $m$ non-negative integers is said to be good if all the elements of $b$ can be made equal to $0$ using the following operation some (possibly, zero) times:
- Select two distinct indices $l$ and $r$ ($1 \leq l \color{red}{<} r \leq m$) and subtract $1$ from all $b_i$ such that $l \leq i \leq r$.
You are given two positive integers $n$, $k$ and a prime number $p$.
Over all $(k+1)^n$ arrays of length $n$ such that $0 \leq a_i \leq k$ for all $1 \leq i \leq n$, count the number of good arrays.
Since the number might be too large, you are only required to find it modulo $p$.
InputEach test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three positive integers $n$, $k$ and $p$ ($3 \leq n \leq 400$, $1 \leq k \leq n$, $10^8 < p < 10^9$) — the length of the array $a$, the upper bound on the elements of $a$ and modulus $p$.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $2 \cdot 10^5$, and $p$ is prime.
OutputFor each test case, on a new line, output the number of good arrays modulo $p$.
ExampleInput4 3 1 998244853 4 1 998244353 3 2 998244353 343 343 998244353Output
4 7 10 456615865Note
In the first test case, the $4$ good arrays $a$ are:
- $[0,0,0]$;
- $[0,1,1]$;
- $[1,1,0]$;
- $[1,1,1]$.
Output
这是一个关于“好数组”的计数问题。一个长度为m的非负整数数组b被认为是“好”的,如果可以通过以下操作(可能零次)使得b的所有元素都变为0:选择两个不同的下标l和r(1≤l
输入输出数据格式:
输入:
- 第一行包含一个整数t(1≤t≤10^3),表示测试用例的数量。
- 每个测试用例的第一行包含三个正整数n、k和p(3≤n≤400,1≤k≤n,10^8 - 保证所有测试用例的n^2之和不超过2×10^5,且p是素数。
输出:
- 对于每个测试用例,输出一行,表示“好数组”的数量模p的结果。
示例:
输入:
```
4
3 1 998244853
4 1 998244353
3 2 998244353
343 343 998244353
```
输出:
```
4
7
10
456615865
```题目大意: 这是一个关于“好数组”的计数问题。一个长度为m的非负整数数组b被认为是“好”的,如果可以通过以下操作(可能零次)使得b的所有元素都变为0:选择两个不同的下标l和r(1≤l