首页 > 其他 > 详细

Sicily 1893. Sell Ticket

时间:2015-03-30 09:18:50      阅读:223      评论:0      收藏:0      [点我收藏+]

1893. Sell Ticket

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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?

Input

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.

Output

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

Sample Input

2
0

Sample Output

2


运用卡特兰数求解


#include <stdio.h>

long long c[31];
int n, i;

void initialize() {
    c[0] = c[1] = 1;
    for (i = 2; i <= 30; i++) {
        c[i] = (4 * i - 2) * c[i - 1] / (i + 1);//记住这个递推公式
    }
}

int main() {
    initialize();
    while (scanf("%d", &n) && n) {
        printf("%lld\n", c[n]);
    }
    return 0;
}                        


Sicily 1893. Sell Ticket

原文:http://blog.csdn.net/u012925008/article/details/44739003

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!