【HDOJ】1023 Train Problem II
【题目】http://acm.hdu.edu.cn/showproblem.php?pid=1023
【报告】
简单粗暴的卡特兰数,不过要用大数才能过呦~
【程序】
// Task: 1023 Train Problem II// Designer: Rsky 2013/08/13
#include
#include
#include
using namespace std;
#define L 1000
int a[L+1];
inline void mult(int x)
{
for (int i=1;i<=L;i++) a[i]*=x;
for (int i=L;i>=1;i--)
{
a[i-1]+=a[i]/10;
a[i]%=10;
}
}
inline void divi(int x)
{
int c=0;
for (int i=1;i<=L;i++)
{
int q=c*10+a[i];
a[i]=q/x;
c=q%x;
}
}
int main()
{
int n;
while (cin >> n)
{
memset(a,0,sizeof(a));
a[L]=1;
for (int i=2*n;i>=n+2;i--)
mult(i);
for (int i=n;i>=1;i--)
divi(i);
int i=0;
while (i
for (;i<=L;i++)
cout << a[i];
cout << endl;
}
return 0;
}
为什么来到这,行将终结、匆忙纷扰、并且完全看不到救赎的世界。

浙公网安备 33010602011771号