题目链接
一开始我光看题目,只想到了n个节点构造二叉树的公式,发现并不对,查了一下资料,实际上是,我之前用的公式是以一个固定的点为根构建 的种数,而此时,我们需要求每一个点都可以为根的情况,所以再乘n!(没想明白?)
代码如下:
#pragma warning(disable:4996);
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
struct biginteger {
int size;
int a[1000];
void init()
{
size = 0;
for (int i = 0;i < 1000;i++)
a[i] = 0;
}
void set(int x) {
init();
do {
a[size++] = x % 10000;
x /= 10000;
} while (x);
}
void output()
{
for (int i = size - 1;i >= 0;i--)
{
if (i != size - 1) printf("%04d", a[i]);
else printf("%d", a[i]);
}
printf("\n");
}
biginteger operator *(const int x)const {
biginteger ret;
ret.init();
int carry = 0;
for (int i = 0;i < size;i++)
{
int tmp = a[i] * x + carry;
ret.a[ret.size++] = tmp % 10000;
carry = tmp / 10000;
}
if (carry != 0) ret.a[ret.size++] = carry % 10000;
return ret;
}
}use;
int main()
{
int n;
while (cin >> n&&n)
{
if (n == 1) {
cout << "1" << endl;continue;
}
use.set(2 * n);
for (int i = n + 2;i < 2 * n;i++) use = use * i;
use.output();
}
}