HDOJ 1131 Count the Trees
题目
题意
给 n 个元素 可得到多少种不同的 树
一下是 2 的 4 种
题解
Cn+2n∗2=n∗2!n+2!
代码
#include <iostream>
#include <iomanip>
#include <cstring>
#define maxnum 100
#define maxint 10000
using namespace std;
struct bigint
{
int m;
int perint[maxnum];
bigint()
{
for(int i = 0;i < maxnum;i++)
perint[i] = 0;
}
bigint & operator*(int b)
{
int c = 0,cur;
for(int i = 0;i <= m;i++)
{
cur = perint[i] * b + c;
perint[i] = cur % maxint;
c = cur / maxint;
}
if(c)
{
m++;
perint[m] = c;
}
return *this;
}
friend ostream & operator<<(ostream &out,bigint & b)
{
out << b.perint[b.m];
for(int i = b.m - 1;i >= 0;i--)
out << setw(4) << setfill('0') << b.perint[i];
return out;
}
};
int main()
{
int nm;
bigint t;
while(cin >> nm && nm)
{
t.perint[0] = 1;
t.m = 0;
for(int i = nm + 2;i <= nm * 2;i++)
t * i;
cout << t << endl;
memset(t.perint,0,sizeof(t.perint));
}
return 0;
}