Codeforces Round 934 (Div. 1)
D1
Counting Is Fun (Easy Version)
Codeforces
2400
原题
← CD2 →
翻译中…

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}{ \lt } 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$.

翻译中…

Input

翻译中…

Each 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 \lt p \lt 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.

翻译中…

Output

翻译中…

For each test case, on a new line, output the number of good arrays modulo $p$.

翻译中…

Note

翻译中…

In the first test case, the $4$ good arrays $a$ are:

翻译中…
  • $[0,0,0]$;
  • $[0,1,1]$;
  • $[1,1,0]$;
  • $[1,1,1]$.
翻译中…

样例

Input #1
4
3 1 998244853
4 1 998244353
3 2 998244353
343 343 998244353
Output #1
4
7
10
456615865
InputCopy OutputCopy
题目信息
题号
1943D1
时间限制
3 s
内存限制
1024 MB
标签
暴力
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。