1 solutions

  • 0
    @ 2025-11-5 15:06:02

    C++ :

    #include<stdio.h>
    #include<string.h>
    
    #define MOD 1000000007
    
    typedef long long LL;
    
    LL f[1010];
    
    int main(){
    	f[0] = 1;
    	for(int i = 1;i <= 1000;++i){
    		f[i] = 0;
    		for(int j = 0;j < i;++j){
    			f[i] += f[j] * f[i - j - 1] % MOD;
    			f[i] %= MOD;
    		}
    	}
    	int T;
    	scanf("%d",&T);
    	for(int cas = 1;cas <= T;++cas){
    		int t;
    		scanf("%d",&t);
    		printf("%d\n",f[t]);
    	}
    	return 0;
    }
    
    

    Java :

    import java.io.*;
    import java.util.*;
    import java.math.*;
    
    public class Main{
    	final static Scanner jin=new Scanner(System.in);
    	static BigInteger C[]=new BigInteger[1005];
    	static BigInteger Catlan(int n){
    		if(!C[n].equals(BigInteger.ZERO))
    			return C[n];
    		BigInteger ans=BigInteger.ZERO;
    		for(int i=0;i<n;i++)
    			ans=ans.add(Catlan(i).multiply(Catlan(n-i-1)));
    		return C[n]=ans.mod(BigInteger.valueOf(1000000007));
    	}
    	public static void main(String args[]){
    		Arrays.fill(C,BigInteger.ZERO);
    		C[0]=C[1]=BigInteger.ONE;
    		int q=jin.nextInt();
    		while(q-->0){
    			int x=jin.nextInt();
    			System.out.println(Catlan(x));
    		}
    	}
    }
    
    • 1

    Information

    ID
    16396
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By