22 July 2014


Problem Description

One day, little pig wants to go to the park for fun. He has just one piece of five dollar and luckily the park sells the ticket for five dollar. 
When he got to the park, there are 2*n people waited in one line for ticket. And just by chance, there were n people have one piece of ten dollar and n people has one piece of five dollar (not include little pig).
The little pig watched the park seller to sell tickets and after a while, 2*n people got their tickets and by another chance, all the people who had 10 dollar had their charge and the seller didn’t use their park’s charge!
Little pig wanted to know how many kinds of permutation that these 2*n people formed?


There are multiply test cases in this problem. One integer n(1<=n<=30) in one line.
The input will be terminated by n=0.


Print one integer in one line which is the number of permutation. 

Sample Input


Sample Output





#include <iostream>
#include <string>

using namespace std;

long long Catelan[33];
void fun()
    memset(Catelan, 0, sizeof(Catelan));
    Catelan[0] = 1,Catelan[1] = 1;
    for(int i(2); i < 33; i++)
            for(int j(0); j<i; j++)
                Catelan[i] += Catelan[j] * Catelan[i-1-j];

int main()
    int n(0);
    while(cin >> n && n)
        cout << Catelan[n] << endl;
    return 0;
题目链接Silicy Online Judge 1893

blog comments powered by Disqus