http://acm.hdu.edu.cn/showproblem.php?pid=1134
规律,比较好找,就是算起来,会有超级大的数出现,模拟乘法和加法
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
typedef unsigned long long ll;
string f[110];
string add(string a,string b){
if(a.length()<b.length()){
string tmp=b;
b=a;
a=tmp;
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
int sum=0,carry=0;
string ans;
ans.clear();
for(int i=0;i<a.length();i++){
if(i<b.length())
sum=a[i]-'0'+b[i]-'0'+carry;
else
sum=a[i]-'0'+carry;
ans += (sum%10+'0');
carry=sum/10;
}
while(carry){
ans+=(carry%10+'0');
carry/=10;
}
reverse(ans.begin(),ans.end());
return ans;
}
string mul(string a,string b){
if(a.length()<b.length()){
string tmp=a;
a=b;
b=tmp;
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
string ans;
ans="";
//cout<<"a"<<a<<"b"<<b<<endl;
int pos,carry=0,sum;
for(int i=0;i<b.length();i++){
for(int j=0;j<a.length();j++){
pos=i+j;
if(pos>=ans.length()){
sum=(b[i]-'0')*(a[j]-'0')+carry;
carry=sum/10;
ans+=(sum%10+'0');
}
else{
sum=(b[i]-'0')*(a[j]-'0')+carry+(ans[pos]-'0');
carry=sum/10;
ans[pos]=(sum%10+'0');
}
}
pos=i+a.length();
while(carry){
if(pos>=ans.length()){
sum= carry%10;
carry=sum/10;
ans += sum+'0';
}
else{
sum = (ans[pos]-'0'+carry)%10;
carry=sum/10;
ans[pos]=sum%10;
}
}
}
reverse(ans.begin(),ans.end());
return ans;
}
void init(){
f[1]="1",f[2]="2",f[3]="5";
string tmp;
for(int i=4;i<=100;i++){
tmp.clear();
for(int j=2;j<=2*i;j+=2){
if(j==2||j==2*i)
tmp = add(tmp,f[i-1]);
else{
tmp = add(tmp,mul(f[(j-2)/2],f[(2*i-j)/2]));
}
}
f[i]=tmp;
//cout<<"**"<<tmp<<endl;
}
}
int main(){
ios::sync_with_stdio(false);
init();
int n;
while(~scanf("%d",&n)){
if(n==-1) break;
cout<<f[n]<<endl;
}
}