大数运算,地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=2084
#include
<
stdio.h
>
#include < stdlib.h >
#include < string.h >
const int OneNode = 1000000 ; // 一位里不能超过OneNode
const int NodeLen = 6 ; // 一位储存NodeLen位,和OneNode必须同时更改,输出部分格式必须跟随这里!!!
const int NumMax = 500 ; // 储存位数限制,真实位数为NumMax*6
struct BigNum
{
unsigned num[NumMax] ;//高位 对 下标大位
unsigned numlen ;
void set(unsigned sm=0){ num[0] = sm ; numlen = 1; }//sm<OneNode
void set(char *string , int strlen)
{
numlen = (strlen-1) / NodeLen + 1 ;
memset (num , 0 , sizeof(unsigned)*numlen );
int temp , i ;
for( i=strlen-1 ; i>=0 ; i-- )
{
temp = i / NodeLen ;
num[temp] = num[temp]*10 + string[strlen-1-i]-'0' ;
}
}
void print()
{
printf("%d",num[numlen-1]);
int i = numlen-1;
while( i )
{
i--;
printf("%06d",num[i]);
}
printf("\n");
}
} ;
void Add(BigNum & a,BigNum & b,BigNum & c) // a+b ->c
{
unsigned lenmax = a.numlen>b.numlen?a.numlen:b.numlen;
c.numlen = lenmax;
unsigned i,carry=0;
for ( i=0 ; i<lenmax ; i++ )
{
c.num[i] = carry ;
if( a.numlen > i )
c.num[i]+= a.num[i];
if( b.numlen > i )
c.num[i]+= b.num[i];
carry = c.num[i] / OneNode ;
c.num[i] %= OneNode ;
}
if ( carry )
{
c.num[i] = carry ;
c.numlen ++;
}
}
void Mul(BigNum & a,BigNum & b,BigNum & c) // a*b ->c
{
unsigned carry = 0 , lenmax = a.numlen+b.numlen-1 ,i,j ;
unsigned __int64 temp ;
c.numlen = lenmax;
for ( i=0 ; i<lenmax ; i++ )
{
temp = carry ;
for ( j=0 ; j<a.numlen ; j++ )
{
if ( i<j )
break;
if ( i-j >= b.numlen )
{
j = i-b.numlen ;
continue;
}
temp += (unsigned __int64)a.num[j] * b.num[i-j] ;
}
carry = temp / OneNode ;
c.num[i] = temp % OneNode ;
}
if(carry)
{
c.num[i] = carry ;
c.numlen ++;
}
}
void Cpy(BigNum & a , BigNum & b) // b-->a
{
a.numlen=b.numlen;
memcpy(a.num,b.num,sizeof(unsigned)*b.numlen);
}
BigNum dp[ 101 ];
BigNum temp, mid;
void cup ()
{
dp[0].set ( "1", 1 );
for ( int i=1; i<101; i++ )
{
dp[i].set( "0", 1 );
for ( int j=2; j<=i*2; j+=2 )
{
Mul ( dp[ (j-2)/2 ], dp[ (2*i-j)/2], temp );
Add ( dp[i], temp, mid );
Cpy ( dp[i], mid );
}
}
}
int main ()
{
int n;
cup ();
while ( scanf ( "%d", &n ) != EOF && n!=-1 )
{
dp[n].print ();
}
return 0;
}
#include < stdlib.h >
#include < string.h >
const int OneNode = 1000000 ; // 一位里不能超过OneNode
const int NodeLen = 6 ; // 一位储存NodeLen位,和OneNode必须同时更改,输出部分格式必须跟随这里!!!
const int NumMax = 500 ; // 储存位数限制,真实位数为NumMax*6
struct BigNum
{
unsigned num[NumMax] ;//高位 对 下标大位
unsigned numlen ;
void set(unsigned sm=0){ num[0] = sm ; numlen = 1; }//sm<OneNode
void set(char *string , int strlen)
{
numlen = (strlen-1) / NodeLen + 1 ;
memset (num , 0 , sizeof(unsigned)*numlen );
int temp , i ;
for( i=strlen-1 ; i>=0 ; i-- )
{
temp = i / NodeLen ;
num[temp] = num[temp]*10 + string[strlen-1-i]-'0' ;
}
}
void print()
{
printf("%d",num[numlen-1]);
int i = numlen-1;
while( i )
{
i--;
printf("%06d",num[i]);
}
printf("\n");
}
} ;
void Add(BigNum & a,BigNum & b,BigNum & c) // a+b ->c
{
unsigned lenmax = a.numlen>b.numlen?a.numlen:b.numlen;
c.numlen = lenmax;
unsigned i,carry=0;
for ( i=0 ; i<lenmax ; i++ )
{
c.num[i] = carry ;
if( a.numlen > i )
c.num[i]+= a.num[i];
if( b.numlen > i )
c.num[i]+= b.num[i];
carry = c.num[i] / OneNode ;
c.num[i] %= OneNode ;
}
if ( carry )
{
c.num[i] = carry ;
c.numlen ++;
}
}
void Mul(BigNum & a,BigNum & b,BigNum & c) // a*b ->c
{
unsigned carry = 0 , lenmax = a.numlen+b.numlen-1 ,i,j ;
unsigned __int64 temp ;
c.numlen = lenmax;
for ( i=0 ; i<lenmax ; i++ )
{
temp = carry ;
for ( j=0 ; j<a.numlen ; j++ )
{
if ( i<j )
break;
if ( i-j >= b.numlen )
{
j = i-b.numlen ;
continue;
}
temp += (unsigned __int64)a.num[j] * b.num[i-j] ;
}
carry = temp / OneNode ;
c.num[i] = temp % OneNode ;
}
if(carry)
{
c.num[i] = carry ;
c.numlen ++;
}
}
void Cpy(BigNum & a , BigNum & b) // b-->a
{
a.numlen=b.numlen;
memcpy(a.num,b.num,sizeof(unsigned)*b.numlen);
}
BigNum dp[ 101 ];
BigNum temp, mid;
void cup ()
{
dp[0].set ( "1", 1 );
for ( int i=1; i<101; i++ )
{
dp[i].set( "0", 1 );
for ( int j=2; j<=i*2; j+=2 )
{
Mul ( dp[ (j-2)/2 ], dp[ (2*i-j)/2], temp );
Add ( dp[i], temp, mid );
Cpy ( dp[i], mid );
}
}
}
int main ()
{
int n;
cup ();
while ( scanf ( "%d", &n ) != EOF && n!=-1 )
{
dp[n].print ();
}
return 0;
}