传送门https://vjudge.net/problem/HDU-1023
解题思路:
大数和卡特兰数
实现代码:
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; const int MAX=100; const int BASE=10000; void multiplay(int a[],int b){ int arr=0; for(int i=MAX-1;i>=0;i--){ arr+=a[i]*b; a[i]=arr%BASE; arr/=BASE; } } void divide(int a[],int b){ int div=0; for(int i=0;i<MAX;i++){ div=div*BASE+a[i]; a[i]=div/b; div%=b; } } int main(){ int a[101][MAX]; memset(a[1],0,sizeof(a[1])); a[1][MAX-1]=1; for(int i=2;i<101;i++){ memcpy(a[i],a[i-1],sizeof(a[i])); multiplay(a[i],4*i-2); divide(a[i],i+1); } int n; while(cin>>n){ int i; for(i=0;i<MAX&&a[n][i]==0;i++); cout<<a[n][i++]; for(;i<MAX;i++){ printf("%04d",a[n][i]); } cout<<endl; } return 0; }