Cattleya number,

Link: https://ac.nowcoder.com/acm/contest/11356/I
Source: Niuke

In order for us not to be card meaning of the questions, here are a topic meaning:
Given a depth limit of not stack stack sequence A_1, A_2, A_3, \ cdots, A_NA
1 , A 2 , A 3 , ⋯, a N , and A_1A . 1 is not the first out stack. Find the number of legal pop sequences. The answer is modulo 998244353998244353. Input description: A number TT in the first line means that Frog has a TT group inquiry. Following the TT lines, each line has a positive integer NN, which represents the number of destinations (number of elements pushed onto the stack). Output description: output a total of TT lines, each line has an answer, the format is similar, see the example for details. The answer may be larger, please output after modulo 998244353998244353. Example 1 Input Copy 3 3 9 24 Output Copy Case #1: 3 Case #2: 3432 Case #3: 508887030 Description

































For the first query in the sample, set the three destinations as AA, BB, and CC, where AA is the first destination, so it cannot be accessed first. There are three legal access sequences:
· B, A, CB, A, C
· B, C, AB, C, A
· C, B, AC, B, A
Remarks:
1 \leq T \leq 2001≤T≤200
1 \leq N \leq 10^51≤N≤10
5

A1 can’t be popped first.
All popping order is Nth Cattelan number.
If A1 is popped first, then all popping order is (N-1) Cattelan number,
so all available play order is H (N)-H (N-1)

Insert picture description here

Insert picture description here

Insert picture description here

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define int long long

const int mod = 998244353;

int qmi(int a, int b, int mod){
    
    
	int res = 1 % mod;
	while(b){
    
    
		if (b & 1)   res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int C(int a, int b){
    
    
	int ans = 1, res = 1;
	for (int i = a, j = 1; j <= b; i --, j ++){
    
    
		ans = ans * i % mod;
		res = res * j % mod;
	}
	
	return (ans * qmi(res, mod - 2, mod) % mod) % mod;
}

signed main(){
    
    
	int T;
	scanf("%lld", &T);
	
	int t = 1;
	while(T --){
    
    
		int n;
		scanf("%lld", &n);
		
		int ans =  (C(2 * n, n) * qmi(n + 1, mod - 2, mod) % mod - C(2 * n - 2, n - 1) * qmi(n, mod - 2, mod) % mod % mod + mod) % mod;
		  printf("Case #%lld: %lld\n", t ++, ans);
	}
}

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/112596735