2021 Niu Ke Winter Holiday Algorithm Basic Training Camp 6 A. Palindrome bracket sequence count

A. Palindrome bracket sequence count

Title link: https://ac.nowcoder.com/acm/contest/9986/A

Title description:

We define a string S to be palindrome, meaning that the left and right inversion of S is the same as S.

We define a string as a sequence of brackets:

  1. The empty string is a sequence of parentheses.
  2. The concatenation of the two bracket sequences P and Q is a bracket sequence.
  3. If P is a bracket sequence,'('+P+')' is a bracket sequence.

Find the number of schemes of the palindrome bracket sequence of length n (0<=n<=10^9), and take the film for 998244353.

Enter a description:

A T in the first line indicates the number of data groups. T<=1000000.

Next T rows, one n per row.

Output description:

T line. For each set of data, your answer.

Example 1:

Input
2
0
1
Output
1
0

Problem-solving ideas:

emm...the huge pit is so great! ! !
Because of the palindrome, the first and last are equal. If both are left parentheses, the first parenthesis cannot be matched. If they are all right parentheses, the last parenthesis cannot be matched. Therefore, when n=0, there is only one case for an empty string, and there is no palindrome sequence when n>0 .

code show as below:

#include<iostream>
using namespace std;
int main()
{
    
    
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
    
    
		scanf("%d",&n);
		if(n==0)printf("1\n");
		else printf("0\n");
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45894701/article/details/114039361