二、stl ,模拟,贪心等 [Cloned]

本文介绍了一道关于卡特兰数的问题,通过给定数值求其对应的卡特兰数,即求出栈顺序的种数。文章提供了一种使用数组存储大数的解决方案,并给出了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题:

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. 

题意:

给出一个数,求他的卡特兰数,及出栈顺序的种数。

题解:

卡特兰数的公式为F(n)=c(2n,n)/(n+1),然而因为要求大数的卡特兰数,所以必须用数组来储存(大数真的无力),wa了好久改改补补才过掉,难点就在公式的大数处理上

代码:AC

#include<stdio.h>
#include<string.h> 
int h[101][121];
int main()
{
    int i,j,k,l,n;
    memset(h, 0, sizeof(h));
    h[0][1]=1;
	h[1][1]=1;
    for(i = 2; i <= 100; ++i)
    {
        for(j = 0; j < i; ++j) 
            for(k = 1; k < 60; ++k)
            for(l = 1; l < 60; ++l)
        	h[i][k + l - 1] += h[j][k] * h[i - j - 1][l];
        for(j = 1; j < 60; ++j)
        {
            h[i][j + 1] += h[i][j] / 10;
            h[i][j] %= 10;
        }
    }
    while(scanf("%d", &n) != EOF)
    {
        i=60;
		while( h[n][--i] == 0 )
		; 
        for(j = i; j > 0; --j)
		printf("%d", h[n][j]);
        printf("\n");
    }
    return 0;
}
	

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值