标准二维表问题

#include 

/*
 *思路: 这是一个卡特兰数列
 * f(1) = 1, f(2) = 1, f(0) = 1;
 * f(n) = f(0)*f(n-1) + f(1)*f(n-2) + .... + f(n-1)*f(0)
 * */

int recursive(int number) {
	int result = 0;
	if (number == 1 || number == 0)
		return 1;
	int i;
	for (i=0; i < number; i++) {
		result += recursive(i)*recursive(number-i-1);
	}
	return result;
}

int main() {
	int value;
	scanf("%d", &value);
	printf("%d\n", recursive(value));
	return 0;
}

你可能感兴趣的:(算法题)