Codeforces Round 934 (Div. 1 ABCD1 题) 讲解

A. MEX Game 1

Problem Statement

Alice and Bob play yet another game on an array a a a of size n n n. Alice starts with an empty array c c c. Both players take turns playing, with Alice starting first.

On Alice’s turn, she picks one element from a a a, appends that element to c c c, and then deletes it from a a a.

On Bob’s turn, he picks one element from a a a, and then deletes it from a a a.

The game ends when the array a a a is empty. Game’s score is defined to be the MEX † ^\dagger of c c c. Alice wants to maximize the score while Bob wants to minimize it. Find game’s final score if both players play optimally.

† ^\dagger The MEX ⁡ \operatorname{MEX} MEX (minimum excludant) of an array of integers is defined as the smallest non-negative integer which does not occur in the array. For example:

  • The MEX of [ 2 , 2 , 1 ] [2,2,1] [2,2,1] is 0 0 0, because 0 0 0 does not belong to the array.
  • The MEX of [ 3 , 1 , 0 , 1 ] [3,1,0,1] [3,1,0,1] is 2 2 2, because 0 0 0 and 1 1 1 belong to the array, but 2 2 2 does not.
  • The MEX of [ 0 , 3 , 1 , 2 ] [0,3,1,2] [0,3,1,2] is 4 4 4, because 0 0 0, 1 1 1, 2 2 2 and 3 3 3 belong to the array, but 4 4 4 does not.

Input

Each test contains multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 2 ⋅ 1 0 4 1 \leq t \leq 2 \cdot 10^4 1t2104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105).

The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 0 ≤ a i < n 0 \le a_i < n 0ai<n).

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, find game’s score if both players play optimally.

Example

Example

input
3
4
0 0 1 1
4
0 1 2 3
2
1 1
output
2
1
0

Note

In the first test case, a possible game with a score of 2 2 2 is as follows:

  1. Alice chooses the element 1 1 1. After this move, a = [ 0 , 0 , 1 ] a=[0,0,1] a=[0,0,1] and c = [ 1 ] c=[1] c=[1].
  2. Bob chooses the element 0 0 0. After this move, a = [ 0 , 1 ] a=[0,1] a=[0,1] and c = [ 1 ] c=[1] c=[1].
  3. Alice chooses the element 0 0 0. After this move, a = [ 1 ] a=[1] a=[1] and c = [ 1 , 0 ] c=[1,0] c=[1,0].
  4. Bob chooses the element 1 1 1. After this move, a = [   ] a=[\,] a=[] and c = [ 1 , 0 ] c=[1,0] c=[1,0].

At the end, c = [ 1 , 0 ] c=[1,0] c=[1,0], which has a MEX of 2 2 2. Note that this is an example game and does not necessarily represent the optimal strategy for both players.

Formalize Description

给定 1 1 1 个长度为 n n n 的序列 a a a,Alice 与 Bob 轮流操作:

  • Alice:选择一个元素,放入数组 c c c,并将该元素在 a a a 数组中删掉
  • Bob:选择一个元素,将该元素在 a a a 数组中删掉

最后 c c c 数组的最大的 M E X \mathrm{MEX} MEX 是多少?

Solution

考虑 Bob 会如何删是最优的,可以发现如果有出现次数为 1 1 1 的数,那么 Bob 一定会删掉出现次数为 1 1 1 中最小的那个数。

证明:如果 Bob 删掉了一个出现次数 ≥ 1 \ge 1 1 的数,那么这时候,该数一定还存在,那么 Alice 就可以选择这个数,Bob 就等同于做了无用功。

所以,最终的答案应该是 min ⁡ ( \min( min(最小的出现次数为 1 1 1 的数,最小的出现次数为 0 0 0 的数 ) ) ),如果两者都不存在,则输出 n n n


Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e5 + 10;

int n;
int a[N], cnt[N];

void solve() {
	cin >> n;

	for (int i = 0; i < n; i ++)
		cnt[i] = 0;
	for (int i = 1; i <= n; i ++)
		cin >> a[i], cnt[a[i]] ++;

	int one = 0;
	for (int i = 0; i < n; i ++)
		if (cnt[i] == 1) {
			if (one) {
				cout << i << endl;
				return;
			}
			one ++;
		} else if (cnt[i] == 0) {
			cout << i << endl;
			return;
		}
	cout << n << endl;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int dt;
	
	cin >> dt;

	while (dt --)
		solve();

	return 0;
}

B. Non-Palindromic Substring

Problem Statement

A string t t t is said to be k k k-good if there exists at least one substring † ^\dagger of length k k k which is not a palindrome ‡ ^\ddagger . Let f ( t ) f(t) f(t) denote the sum of all values of k k k such that the string t t t is k k k-good.

You are given a string s s s of length n n n. You will have to answer q q q of the following queries:

  • Given l l l and r r r ( l < r l < r l<r), find the value of f ( s l s l + 1 … s r ) f(s_ls_{l + 1}\ldots s_r) f(slsl+1sr).

† ^\dagger A substring of a string z z z is a contiguous segment of characters from z z z. For example, “ d e f o r \mathtt{defor} defor”, “ c o d e \mathtt{code} code” and “ o \mathtt{o} o” are all substrings of “ c o d e f o r c e s \mathtt{codeforces} codeforces” while “ c o d e s \mathtt{codes} codes” and “ a a a \mathtt{aaa} aaa” are not.

‡ ^\ddagger A palindrome is a string that reads the same backwards as forwards. For example, the strings “ z \texttt{z} z”, “ aa \texttt{aa} aa” and “ tacocat \texttt{tacocat} tacocat” are palindromes while “ codeforces \texttt{codeforces} codeforces” and “ ab \texttt{ab} ab” are not.

Input

Each test contains multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 2 ⋅ 1 0 4 1 \leq t \leq 2 \cdot 10^4 1t2104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n n n and q q q ( 2 ≤ n ≤ 2 ⋅ 1 0 5 , 1 ≤ q ≤ 2 ⋅ 1 0 5 2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5 2n2105,1q2105), the size of the string and the number of queries respectively.

The second line of each test case contains the string s s s. It is guaranteed the string s s s only contains lowercase English characters.

The next q q q lines each contain two integers, l l l and r r r ( 1 ≤ l < r ≤ n 1 \le l < r \le n 1l<rn).

It is guaranteed the sum of n n n and the sum of q q q both do not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each query, output f ( s l s l + 1 … s r ) f(s_ls_{l + 1}\ldots s_r) f(slsl+1sr).

Example

Example

input
5
4 4
aaab
1 4
1 3
3 4
2 4
3 2
abc
1 3
1 2
5 4
pqpcc
1 5
4 5
1 3
2 4
2 1
aa
1 2
12 1
steponnopets
1 12
output
9
0
2
5
5
2
14
0
2
5
0
65

Note

In the first query of the first test case, the string is a a a b \mathtt{aaab} aaab. a a a b \mathtt{aaab} aaab, a a b \mathtt{aab} aab and a b \mathtt{ab} ab are all substrings that are not palindromes, and they have lengths 4 4 4, 3 3 3 and 2 2 2 respectively. Thus, the string is 2 2 2-good, 3 3 3-good and 4 4 4-good. Hence, f ( a a a b ) = 2 + 3 + 4 = 9 f(\mathtt{aaab}) = 2 + 3 + 4 = 9 f(aaab)=2+3+4=9.

In the second query of the first test case, the string is a a a \mathtt{aaa} aaa. There are no non-palindromic substrings. Hence, f ( a a a ) = 0 f(\mathtt{aaa}) = 0 f(aaa)=0.

In the first query of the second test case, the string is a b c \mathtt{abc} abc. a b \mathtt{ab} ab, b c \mathtt{bc} bc and a b c \mathtt{abc} abc are all substrings that are not palindromes, and they have lengths 2 2 2, 2 2 2 and 3 3 3 respectively. Thus, the string is 2 2 2-good and 3 3 3-good. Hence, f ( a b c ) = 2 + 3 = 5 f(\mathtt{abc}) = 2 + 3 = 5 f(abc)=2+3=5. Note that even though there are 2 2 2 non-palindromic substrings of length 2 2 2, we count it only once.

Formalize Description

给定一个长度为 n n n 的字符串,接下来有 q q q 次询问,每次询问给定 l , r l,r l,r,求出 s l ∼ r s_{l\sim r} slr 这个字符串中长度之和,使得该长度满足至少有 1 1 1 个不是回文串的子串

Solution

Key Point: 观察性质是做这道题目最关键的一步

由于,如果所有子串都是回文串的情况极少,所以不妨探讨一下:

  • 如果长度为偶数全都是回文串,则如果第 i i i 位填了字符 t t t,那么第 i + 1 i+1 i+1 位也一定是字符 t t t,因为长度为 2 2 2 的要回文。所以,当且仅当整个串全部相同时,才会全都是回文串。
  • 如果长度为奇数全都是回文串,那么字符全都相同显然仍为 1 1 1 种情况;或者是 a   b   a   b a\ b\ a\ b a b a b 的形式也是可以的,即规定了前 2 2 2 个字符,后面的字符可以相继推导出来,而这是交替的形式

综上所述,其实就这 2 2 2 种情况,直接分类讨论判断即可。注意,如果这个序列本身是回文串,那么要先减掉这个序列的长度,判断某个序列是否为回文串用马拉车算法即可。


Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 4e5 + 10;

int n, q;
string s;
int p[N], f1[N], f2[N];

void manacher(string ts) {
	int mr = 1, mid, m = ts.size() - 1;

	for (int i = 1; i <= m; i ++) {
		if (i < mr) p[i] = min(p[mid * 2 - i], mr - i);
		else p[i] = 1;
		while (ts[i - p[i]] == ts[i + p[i]]) p[i] ++;
		if (i + p[i] > mr) {
			mr = i + p[i];
			mid = i;
		}
	}
}

void solve() {
	cin >> n >> q >> s;

	string tmp;
	tmp += "$#";
	for (auto v : s)
		tmp += v, tmp += '#';
	tmp += '^', tmp = ' ' + tmp;
	s = ' ' + s;
	manacher(tmp);

	f1[n] = f2[n] = f2[n + 1] = n;
	for (int i = n - 1; i >= 1; i --) {
		f1[i] = s[i] == s[i + 1] ? f1[i + 1] : i;
		f2[i] = s[i] == s[i + 2] ? f2[i + 2] : i;
	}

	while (q --) {
		int l, r;
		cin >> l >> r;

		int res = (r - l + 3) * (r - l) / 2;
		if (p[l + r + 1] - 1 >= r - l + 1) res -= (r - l + 1);
		if ((r - l + 1) & 1) {
			if (f2[l] >= r && f2[l + 1] >= r - 1) res -= (r - l + 2) * ((r - l >> 1) - 1) / 2;
			if (f1[l] >= r) res -= (2 + r - l) * (r - l >> 1) / 2;
		} else {
			if (f2[l] >= r - 1 && f2[l + 1] >= r) res -= (3 + r - l) * (r - l - 1 >> 1) / 2;
			if (f1[l] >= r) res -= (1 + r - l) * (r - l - 1 >> 1) / 2;
		}

		cout << res << endl;
	}
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int dt;
	cin >> dt;

	while (dt -- )
		solve();

	return 0;
}

C. Tree Compass

Problem Statement

You are given a tree with n n n vertices numbered 1 , 2 , … , n 1, 2, \ldots, n 1,2,,n. Initially, all vertices are colored white.

You can perform the following two-step operation:

  1. Choose a vertex v v v ( 1 ≤ v ≤ n 1 \leq v \leq n 1vn) and a distance d d d ( 0 ≤ d ≤ n − 1 0 \leq d \leq n-1 0dn1).
  2. For all vertices u u u ( 1 ≤ u ≤ n 1 \leq u \leq n 1un) such that dist † ( u , v ) = d \text{dist}^\dagger(u,v)=d dist(u,v)=d, color u u u black.

Construct a sequence of operations to color all the nodes in the tree black using the minimum possible number of operations. It can be proven that it is always possible to do so using at most n n n operations.

† ^\dagger dist ( x , y ) \text{dist}(x, y) dist(x,y) denotes the number of edges on the (unique) simple path between vertices x x x and y y y on the tree.

Input

Each test contains multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 200 1 \leq t \leq 200 1t200) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 3 1 \le n \le 2 \cdot 10^3 1n2103) — the number of vertices of the tree.

The following n − 1 n - 1 n1 lines of each test case describe the edges of the tree. The i i i-th of these lines contains two integers u i u_i ui and v i v_i vi ( 1 ≤ u i , v i ≤ n 1 \le u_i, v_i \le n 1ui,vin, u i ≠ v i u_i \neq v_i ui=vi), the indices of the vertices connected by the i i i-th edge.

It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 3 2 \cdot 10^3 2103.

Output

For each test case, first output a single integer o p op op ( 1 ≤ o p ≤ n ) (1 \le op \le n) (1opn), the minimum number of operations needed to color all vertices of the tree black.

Then, output o p op op lines, each containing 2 2 2 integers. The i i i-th line should contain the values of v v v and d d d chosen for the i i i-th operation ( 1 ≤ v ≤ n 1 \le v \le n 1vn, 0 ≤ d ≤ n − 1 0 \le d \le n - 1 0dn1)

You must guarantee that at the end of o p op op operations, all vertices are colored black.

If there are multiple solutions, you may output any one of them.

Example

Example

input
4
1
2
1 2
4
1 2
1 3
1 4
7
2 7
3 2
6 4
5 7
1 6
6 7
output
1
1 0
2
1 1
2 1
2
1 1
2 1
3
6 1
7 1
2 1

Note

In the first test case, there is only one possible operation, and performing it gives us a valid answer.

In the second test case, the first operation colors vertex 2 2 2 black, and the second operation colors vertex 1 1 1 black. It can be shown that it is impossible to color both vertices black in one operation, so the minimum number of operations needed is 2 2 2. Another possible solution is to use the 2 2 2 operations: ( u , r ) = ( 1 , 0 ) (u, r) = (1, 0) (u,r)=(1,0) and ( u , r ) = ( 2 , 0 ) (u, r) = (2, 0) (u,r)=(2,0).

In the third test case, the first operation colors vertices 2 2 2, 3 3 3 and 4 4 4 black, and the second operation colors vertex 1 1 1 black. Again, it can be shown that it is impossible to color all vertices black in 1 1 1 operation, so the minimum number of operations needed is 2 2 2.

In the fourth test case, the first operation colors vertices 4 4 4, 1 1 1 and 7 7 7 black, the second operation colors vertices 2 2 2, 5 5 5 and 6 6 6 black while the third operation colors vertices 3 3 3 and 7 7 7 black. Notice that it is allowed to color vertex 7 7 7 black twice.

Thus, each node was marked at least once, with node 7 7 7 marked twice. It can be shown that it is impossible to color all vertices black in fewer than 3 3 3 moves.

Formalize Description

给定一棵 n n n 个节点的树,每次可以将到某个节点距离全部相等的点涂黑,问最后全部点涂黑的方案数。

Solution

Key Point:

  1. 如果对于树的问题没有很好的思路,可以先考虑链的情况
  2. 树的问题如果不是 DP,那么就要考虑直径,中心,重心……

对于该题,如果是一条链,那么直接从中间的点向外依次不断涂黑即可。

那么,对于树的情况,链是中心,那树是不是也是其中一条链的中心呢?答案是直径的中心,因为当时直径的中心的时候,则操作数其实是直径的长度除 2 2 2,因为对于依次操作,其实是将以这个点为根的树某一层全部涂黑,所以直径中心是最优的。

不过,可能直径的长度为偶数,此时就需要另一种讨论。

有时候,中间的 2 2 2 个点都需要,比如说:
在这里插入图片描述

只用 1 1 1 号点,答案应该是 3 3 3,但是如果按如下方式做,答案是 2 2 2
在这里插入图片描述

绿色点为 1 1 1 号点图的,红色为 2 2 2 号点图的。所以,其实每个点都将距离他为奇数的点涂掉即可。


Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 2e3 + 10;

int n;
std::vector<int> G[N];
int dep[N], mx = -1, p[2], idx;
std::vector<int> path, res;

void dfs(int u, int fa) {
	if (dep[u] > mx)
		mx = dep[u], p[idx] = u;
	for (auto v : G[u]) {
		if (v == fa) continue;
		dep[v] = dep[u] + 1;
		dfs(v, u);
	}
}

void dfs2(int u, int fa) {
	path.emplace_back(u);
	if (u == p[1]) res = path;
	for (auto v : G[u]) {
		if (v == fa) continue;
		dfs2(v, u);
	}
	path.pop_back();
}

void solve() {
	cin >> n;

	for (int i = 1; i <= n; i ++)
		G[i].clear();
	path.clear(), idx = 0;

	int u, v;
	for (int i = 1; i < n; i ++)
		cin >> u >> v, G[u].emplace_back(v), G[v].emplace_back(u);

	mx = -1, dep[1] = 1, dfs(1, -1);
	mx = -1, dep[p[0]] = 1, dfs(p[idx ++], -1);
	path.emplace_back(0);
	dfs2(p[0], -1);

	if (mx & 1) {
		int mid = res[res.size() + 1 >> 1];
		int mxd = mx / 2;
		cout << mxd + 1 << endl;
		for (int i = 0; i <= mxd; i ++)
			cout << mid << " " << i << endl;
	} else {
		int mid1 = res[res.size() >> 1], mid2 = res[res.size() / 2 + 1];
		mx = -1, dep[mid1] = 1, dfs(mid1, -1);
		int mx1 = mx;
		mx = -1, dep[mid2] = 1, dfs(mid2, -1);
		int mx2 = mx;
		cout << mx1 / 2 + mx2 / 2 << endl;
		for (int i = 1; i < mx1; i += 2)
			cout << mid1 << " " << i << endl;
		for (int i = 1; i < mx2; i += 2)
			cout << mid2 << " " << i << endl;
	}
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int dt;
	
	cin >> dt;

	while (dt --)
		solve();

	return 0;
}

D1. Counting Is Fun (Easy Version)

Problem Statement

This is the easy version of the problem. The only difference between the two versions is the constraint on n n n. You can make hacks only if both versions of the problem are solved.

An array b b b of m m m non-negative integers is said to be good if all the elements of b b b can be made equal to 0 0 0 using the following operation some (possibly, zero) times:

  • Select two distinct indices l l l and r r r ( 1 ≤ l < r ≤ m 1 \leq l \color{red}{<} r \leq m 1l<rm) and subtract 1 1 1 from all b i b_i bi such that l ≤ i ≤ r l \leq i \leq r lir.

You are given two positive integers n n n, k k k and a prime number p p p.

Over all ( k + 1 ) n (k+1)^n (k+1)n arrays of length n n n such that 0 ≤ a i ≤ k 0 \leq a_i \leq k 0aik for all 1 ≤ i ≤ n 1 \leq i \leq n 1in, count the number of good arrays.

Since the number might be too large, you are only required to find it modulo p p p.

Input

Each test contains multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three positive integers n n n, k k k and p p p ( 3 ≤ n ≤ 400 3 \leq n \leq 400 3n400, 1 ≤ k ≤ n 1 \leq k \leq n 1kn, 1 0 8 < p < 1 0 9 10^8 < p < 10^9 108<p<109) — the length of the array a a a, the upper bound on the elements of a a a and modulus p p p.

It is guaranteed that the sum of n 2 n^2 n2 over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105, and p p p is prime.

Output

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

Example

Example

input
4
3 1 998244853
4 1 998244353
3 2 998244353
343 343 998244353
output
4
7
10
456615865

Note

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

  • [ 0 , 0 , 0 ] [0,0,0] [0,0,0];
  • [ 0 , 1 , 1 ] [0,1,1] [0,1,1];
  • [ 1 , 1 , 0 ] [1,1,0] [1,1,0];
  • [ 1 , 1 , 1 ] [1,1,1] [1,1,1].

Formalize Description

称一个长度为 n n n 的序列为好的,当且仅当这个序列可以通过每次将一个 不为 1 1 1 的区间减 1 1 1,最终能减为全 0 0 0。问有多少个长度为 n n n 的序列,每个数的范围为 [ 0 , k ] [0, k] [0,k],使得该序列是好的。

Solution

一个序列是好的的充分必要条件为 ∀ i , a i ≤ a i − 1 + a i + 1 \forall i, a_i\le a_{i-1}+a_{i+1} i,aiai1+ai+1

证明:

充分性:两边减的过程中,一定可以把 a i a_i ai 也见到 0 0 0

必要性:反证法,若存在某个好的序列,使得 ∃ i , a i > a i − 1 + a i + 1 \exist i,a_i>a_{i-1}+a_{i+1} i,ai>ai1+ai+1,那么两边最终减到 0 0 0 了之后, a i a_i ai 还是有值的,但是不能减长度为 1 1 1 的区间所以一定不是好的序列,与假设矛盾,证毕。

所以,只需判断有多少的序列满足这个条件即可。

f i , j , k f_{i,j,k} fi,j,k 表示前 i i i 个数,当前填 j j j,上一个位置填 k k k 的方案数,则有: f i , j , k = ∑ f i − 1 , k , t [ k ≤ j + t ] f_{i,j,k}=\sum f_{i-1,k,t}[k\le j+t] fi,j,k=fi1,k,t[kj+t]

这是 O ( n 4 ) O(n^4) O(n4) 的,通过前缀和优化就可以达到 O ( n 3 ) O(n^3) O(n3)

Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 4e2 + 10;

int n, k, p;
int f[2][N][N], g[2][N][N];

void add(int &a, int b) {
	a = (a + b + p) % p;
}

void solve() {
	cin >> n >> k >> p;

	for (int i = 0; i < 2; i ++)
		for (int j = 0; j <= k; j ++)
			for (int l = 0; l <= k; l ++)
				f[i][j][l] = g[i][j][l] = 0;
	for (int i = 0; i <= k; i ++)
		for (int j = 0; j <= k; j ++)
			if (i >= j) f[0][i][j] = 1, add(g[0][i][j], g[0][i][j - 1] + 1);
			else add(g[0][i][j], g[0][i][j - 1]);
	for (int i = 3; i <= n; i ++) {
		for (int j = 0; j <= k; j ++)
			for (int l = 0; l <= k; l ++)
				f[i & 1][j][l] = g[i & 1][j][l] = 0;
		for (int j = 0; j <= k; j ++)
			for (int l = 0; l <= k; l ++) {
				add(f[i & 1][j][l], g[(i & 1) ^ 1][l][k] - (l - j > 0 ? g[(i & 1) ^ 1][l][l - j - 1] : 0));
				add(g[i & 1][j][l], g[i & 1][j][l - 1] + f[i & 1][j][l]);
			}
	}

	int res = 0;
	for (int i = 0; i <= k; i ++)
		for (int j = 0; j <= k; j ++)
			if (j >= i)
				add(res, f[n & 1][i][j]);

	cout << res << endl;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int dt;
	
	cin >> dt;

	while (dt --)
		solve();

	return 0;
}

最后祝大家早日在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-19 22:44:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-19 22:44:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-19 22:44:05       87 阅读
  4. Python语言-面向对象

    2024-03-19 22:44:05       96 阅读

热门阅读

  1. 爬虫基本原理实现以及问题解决

    2024-03-19 22:44:05       46 阅读
  2. 系统架构设计师笔记第37期:数据访问层设计

    2024-03-19 22:44:05       42 阅读
  3. PyTorch学习笔记之基础函数篇(十二)

    2024-03-19 22:44:05       39 阅读
  4. [LLM]大模型八股知识点(一)

    2024-03-19 22:44:05       33 阅读
  5. 常见的几个Python技术难题

    2024-03-19 22:44:05       39 阅读
  6. 有什么小程序适合个人开发?

    2024-03-19 22:44:05       45 阅读
  7. 开发指南013-国际化-前台部分

    2024-03-19 22:44:05       43 阅读