hdu 1134 Game of Connections
主要考察卡特兰数,大数乘法,除法……
链接http://acm.hdu.edu.cn/showproblem.php?pid=1134
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int an[102][102];
void mul(int i)
{
int k,j,t=0,a=4*i-2,b=i+1,temp;
k=100;
while(an[i-1][k]<=0||an[i-1][k]>9) k--;
for(j=0;j<=k;j++)
{
an[i][j]=an[i-1][j]*a+t;
if(an[i][j]>9)
{
t=an[i][j]/10;
an[i][j]%=10;
}
else t=0;
}
while(t!=0)
{
an[i][j++]=t%10;
t/=10;
}
j--;
t=0;
while(j>=0)
{
temp=t*10+an[i][j];
an[i][j]=temp/b;
t=temp%b;
j--;
}
}
int main()
{
int i,n;
an[0][0]=1;an[1][0]=1;
for(i=2;i<=100;i++)
mul(i);
while(cin>>n&&n!=-1)
{
i=100;
while(an[n][i]<=0||an[n][i]>9) i--;
for(;i>=0;i--)
cout<<an[n][i];
cout<<endl;
}
return 0;
}