C - Train Problem II-- Cartland number

Topic Link _HDU-1023

topic

As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.

input

The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.

output

For each test case, you should output how many ways that all the trains can get out of the railway.

Sample Input

1

2

3

10

Sample Output

1

2

5

16796

Ideas:

Look closely, is to let you find the number Cartland, but the scope of this number of big points, will burst long long, so use arrays for storage. This question should be the core is to make large numbers to seek a smaller number of multiplication and division.

And this multiplication and division (because it is operating on a smaller number) is so simple simulation we usually hand count of the number of multiplication and division.

Specific code to achieve the following:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[2005];
void mu(int k)
{
    int c=0;
    for(int i=1;i<=2000;i++)
    {
        int u=a[i]*k+c;
        a[i]=u%10;
        c=u/10;
    }

}
void chu(int k)
{
    int c=0;
    for(int i=2000;i>=1;i--)
    {
        int u=a[i]+c;
        a[i]=u/k;
        c=u%k*10;
    }
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
         a[1]=1;
        for(int i=n+1;i<=2*n;i++)
        {
            mu(i);
        }
        for(int i=1;i<=n+1;i++)
        {
            chu(i);
        }
        int flog=0;
        for(int i=2000;i>=1;i--)
        {
            if(a[i]!=0)
            {
                flog=1;
            }
            if(flog==1)
            {
                printf("%d",a[i]);
            }
        }
        printf("\n");
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/HANGANG/p/11900855.html