HDU 2067:
#include <bits/stdc++.h>
using namespace std;
long long catalan[42];
void Catalan(int n) {
catalan[0] = catalan[1] = 1;
for(int i = 2; i <= n; ++i) {
catalan[i] = 0;
for(int j = 0; j < i; ++j) {
catalan[i] += catalan[j] * catalan[i-j-1];
}
}
}
int main() {
int n, cas = 1;
Catalan(35);
while(scanf("%d", &n) != EOF) {
if(n == -1) break;
printf("%d %d %lld\n", cas++, n, 2 * catalan[n]);
}
return 0;
}
HDU 1023:
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static BigInteger[] catalan = new BigInteger[108]; // Objects must be initialized befor use
public void Catalan() {
catalan[0] = catalan[1] = BigInteger.ONE;
for(int i = 2; i <= 100; ++i) {
catalan[i] = BigInteger.ZERO;
for(int j = 0; j < i; ++j) {
catalan[i] = catalan[i].add(catalan[j].multiply(catalan[i-j-1]));
}
}
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
Main obj = new Main();
obj.Catalan();
while(cin.hasNext()) {
int n;
n = cin.nextInt();
System.out.println(catalan[n]);
}
}
}
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static BigInteger[] catalan = new BigInteger[108];
public void Catalan() {
catalan[0] = catalan[1] = BigInteger.ONE;
for(int i = 2; i <= 100; ++i) {
catalan[i] = BigInteger.ZERO;
for(int j = 0; j < i; ++j) {
catalan[i] = catalan[i].add(catalan[j].multiply(catalan[i-j-1]));
}
}
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
Main obj = new Main();
obj.Catalan();
while(cin.hasNext()) {
int n;
n = cin.nextInt();
if(n == 0) {
break;
}
BigInteger pro = BigInteger.ONE;
for(long i = 2; i <= n; ++i) {
pro = pro.multiply(BigInteger.valueOf(i));
}
System.out.println(pro.multiply(catalan[n]));
}
}
}