UVa 10223 - How many nodes ?

称号:气你一个整数n,问:多少节点可以产生n不同的二叉树。

分析:数论,卡特兰数。根据定义,你可以。

说明:请参阅http://blog.csdn.net/mobius_strip/article/details/39229895

#include <iostream>
#include <cstdlib>

using namespace std;

long long Cat[100];

int main()
{
	Cat[0] = 1LL;
	for (int i = 1 ; i < 20 ; ++ i)
		Cat[i] = Cat[i-1]*(2*i+1)*2/(i+2);
	
	int n;
	while (cin >> n)
	for (int i = 0 ; i < 20 ; ++ i)
		if (Cat[i] == n) {
			cout << i+1 << endl;
			break;
		}
	return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-09-09 17:43  phlsheji  阅读(293)  评论(0编辑  收藏  举报