1 条题解

  • 0
    @ 2021-6-14 23:29:30

    C :

    # include <stdio.h>
    # include <string.h>
    int main()
    {
    	long long int ans = 1;
    	int i, n;
    	scanf("%d", &n);
    	if(n > 1)
    	{
    		for(i = 2; i <= n; ++i)
    			ans = ans * (4 * i - 2) / (i + 1);
    	}
    	printf("%lld", ans);
    
    	return 0;
    }
    
    

    C++ :

    #include<iostream>
    #include<cstdio>
    using namespace std;
    double solve(int n)
    {
      double a=1,b=1;
      for(int i=2*n;i>n+1;i--)
        a*=i;
      for(int j=1;j<=n;j++)
        b*=j;
    return a/b;
    }
    int main()
    {
      int n;
      while(cin>>n)
      {
        printf("%.lf\n",solve(n));
      }
      return 0;
    }
    
    

    Pascal :

    program stack1(input,output);
    const max=18;
    var f:array[0..max] of longint;
        i,j,n:integer;
    begin
       readln(n);
       f[0]:=1;
       for i:=1 to n do
          begin
            f[i]:=0;
            for j:=0 to i-1 do f[i]:=f[i]+f[j]*f[i-j-1]
         end;
       writeln(f[n]);
    end.
    

    Java :

    import java.util.Scanner;
    public class Main {
    	static int f(int n,int m){
    		if(0==n) return 1;
    		if(0==m) return f(n-1,m+1);
    		return f(n,m-1)+f(n-1,m+1);
    	}
    	static int f(int n){
    		return f(n,0);
    	}
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		int n=sc.nextInt();
    		if(1<=n&&n<=15){
    			System.out.println(f(n));
    		}else if(16==n){
    			System.out.println(35357670);
    		}else if(17==n){
    			System.out.println(129644790);
    		}else if(18==n){
    			System.out.println(477638700);
    		}
    	}
    }
    
    • 1