HDU1023 (卡特兰数)

hdu1023(广度优先搜索) //这个题目的难度我感觉还是蛮大的,做完这个题目了,感觉一下子轻松多了,整个人都舒服很多,那么来说说这个题目吧,//这个题目里面有优先队列,广度搜索,还有栈,回溯,整个题目的意思很简单,就是在最短的时间内到达最角落的地方,(0.0)-》(n-1,m-1)//这里面感觉最难的就是回溯,感觉在这里如何把路径找到才是最重要的。#include #include #include #include 阅读详情

题目:HDU023
N个火车出栈入栈组合数问题,很明显是属于卡特兰数的应用

卡特兰数的前几个数为:
1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845
递推式为:h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) ) (n>=2)
当然它还有其他的递推式,看一下这位大佬的就知道了:传送门

好吧,先来看一下当n=100时,是多大的一个数吧:
896519947090131496687170070074100632420837521538745909320

没错,就是这么长,那么即使我们使用long long 也是不够用的,所以我们需要使用大数运算。

那么就来看一下具体的代码实现吧:

#include<bits/stdc++.h>
using namespace std;
int a[110][110];
void cantalan()
{
    memset(a,0,sizeof(a));  //初始化
    a[1][0]=1;              //a[i][0]表示第 i 个数的位数
    a[1][1]=1;
    a[2][0]=1;
    a[2][1]=2;
    int len=1;
    for(int i=3; i<=100; i++)
    {
        int yu=0;
        for(int j=1; j<=len; j++)
        {
            a[i][j]=a[i-1][j]*(4*i-2)+yu;
            yu=a[i][j]/10;               // yu 表示进位
            a[i][j]%=10;
        }
        while(yu)
        {
            a[i][++len]=yu%10;
            yu/=10;
        }
        for(int j=len; j>=1; j--)        //模拟除法
        {
            int t=a[i][j]+yu*10;
            a[i][j]=t/(i+1);
            yu=t%(i+1);
        }
        while(!a[i][len])            //消除前导0
            len--;
        a[i][0]=len;
    }
}
int main()
{
    cantalan();
    int n;
    while(cin>>n)
    {
        for(int i=a[n][0]; i>0; i--)   //由于存的时候时逆着存的,输出也应该从后往前
            cout<<a[n][i];
        cout<<endl;
    }
    return 0;
}

卡特兰数(HDU 1023) 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。 卡特兰数 前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 阅读详情

相关推荐

[SWPUCTF 2018]SimplePHP--一道简单的Phar反序列化题目

题目就不贴了,直接给出利用链①:echo会触发__toString魔术方法,所以这里的$this->test应该是Show类实例化的对象show②:这里应该使$this->str['str']为Test类实例化后的对象test,然后test->source会触发__get魔术方法(因为Test类没有名为source的成员变量,所以会触发get魔术方法,并且$key=source)③④:调用get方法,$...

Dream' 1261

HDU 1023(卡特兰数 数学)

题意是求一列连续升序的数经过一个栈之后能变成的不同顺序的数目。 开始时依然摸不着头脑,借鉴了别人的博客之后,才知道这是卡特兰数,卡特兰数的计算公式是:a( n ) = ( ( 4*n-2 ) / ( n+1 ) * a( n-1 ) ); 用一个二维数组,a[ i ][ 0 ] 表示第 i 个卡特兰数的位数,a[ i ][ j ] ( j != 0) 中存第 i 个卡特兰数从低位...

b338865802883204的博客 206

告别仿真报错!手把手教你为Intel MAX10 FPGA定制IBIS模型(附Allegro Skill工具)

本文详细介绍了为Intel MAX10 FPGA定制IBIS模型的完整流程,解决信号完整性仿真中的管脚映射问题。通过Allegro Skill工具自动化处理管脚信息,优化IBIS模型关键段落,提升仿真效率和精度,适用于高速数字电路设计。

weixin_33217202的博客 330

hdu 1023(大数+卡特兰数)

题目:和那个I有关,是问火车按一定顺序进站,出战的顺序有多少中。 分析: 典型的卡特兰数,但本题数量巨大  所以采用大数来写  java中提供了大数类,所以用了java写 卡特兰数公式:h(n)=C(2n,n)/(n-1)  递推式: h(n)=h(n-1)*(4*n-2)/(n+1); 代码如下: import java.io.*; import java.math.Bi

北门的智慧 1033

calibre QRC提取寄生参数

typical将上面的文件QCI_flow里面的文件 在Cp 到当前 ,其实应该是某几个文件,但是我给忘记了 就全cp过来了 ,无影响,不过也希望大佬指正。

2202_75711937的博客 1545

深入解析组合逻辑环(combinational loop)的成因与解决方案

本文深入解析了数字电路设计中组合逻辑环(combinational loop)的成因与危害。通过边沿检测和中断轮询(round_robin)仲裁器等实例,揭示了代码如何意外形成环路,并对比了插入触发器、重构逻辑以及状态机思维三种核心解决方案,帮助硬件工程师从根本上避免这一常见设计陷阱,确保电路稳定可靠。

weixin_28278377的博客 319

HDU-1023 Train Problem II

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目大意: 给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能。 解题思路: 模拟栈的问题而已。 这道题其实也是组合数学卡特兰数的一个典型应用而已。下面就介绍一下卡特兰数。 ========================================...

peizhiinfo 181

【异常】OpenClaw提示异常 1302:您的账户已达到速率限制,请您控制请求频率

摘要:系统返回1302错误码提示"账户已达到速率限制",表明请求频率超过服务阈值。主要原因是并发请求数达上限或请求过于密集。解决方案包括:降低并发请求量、引入请求队列机制平滑流量,或根据服务规则提升账户权益等级以获取更高并发额度。建议优先优化请求频率控制策略,避免触发系统限流机制。

奶爸的编程之路,也就一周冷个三天 1169

HDU1023(Catalan数)

Catanlan数 维基百科:http://zh.wikipedia.org/zh/%E5%8D%A1%E5%A1%94%E5%85%B0%E6%95%B0 hdu1023   题意:一堆火车以严格的顺序到一个站里,问出来的时候有多少种顺序。   C[0] = 1   C[n] = C[n-1]*(4*n-2)/(n+1) import java.math.*;

天亮说晚安 1740

基于YOLOv5s的RK3588多线程部署16FPS暴涨到120FPS 轻量化深度学习部署实战教程(包括性能优化与加速)37

本文介绍了如何在RK3588平台上利用线程池优化YOLOv5模型的推理性能。RK3588内置3个NPU核心,支持多核并行处理。作者设计了一个线程池架构:1个线程负责数据读取,10个线程处理NPU运算,1个线程输出结果。该架构包含任务队列、线程管理和工作线程三个核心组件,通过合理设置线程数、任务队列大小等参数确保性能稳定。文章提供了详细的C++实现代码,包括线程池初始化、任务提交、结果获取等功能模块,并讨论了多线程同步和内存管理的关键技术要点。该方案可显著提升深度学习模型在嵌入式设备上的部署效率。

FJN110的博客 9235

PCL 模型滤波器【2025最新版】

根据给定的模型系数在点云中提取对应于模型的点云数据。博客长期更新,本文最新更新时间为:2025年6月17日。

点云侠的博客 4387

HDU 1023 Train Problem II (打表求解卡特兰数)

HDU 1023 Train Problem Ⅱ:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题面: Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7629    Accepted

而濡木染 656

ESP8266-Arduino编程实例-TEA5767收音机模块驱动

TEA5767HN 是一款用于低压应用的单芯片电子调谐 FM 立体声收音机,具有完全集成的中频 (IF) 选择性和解调功能,频率范围从76—108MHZ自动数字调谐。 该收音机完全无需调整,高灵敏度,高稳定性,低噪音,收音模块。只需要最少的小型低成本外部组件。 收音机可以调到欧洲、美国和日本的 FM 波段。...

视觉与物联智能 1986

HDU1023 Train Problem II(卡特兰数+大数)

HDU1023 Train Problem II(卡特兰数+大数) HDU1023 Train Problem II(卡特兰数+大数) 题意 思路 AC代码 原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题意 此题是Train Problem I 的一个衍生,有一个站台(可以看做是栈,先进后出),给你一个数代表火车...

HuiSeKongHuan的博客 532

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU1023 Train Problem II【卡特兰数+大数+亿进制+打表】

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10175    Accepted Submission(s): 5440 Problem Description As we all kn

海岛Blog 940

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

HDU1023-卡特兰数

1.题目链接。题意十分的简单,一组数据经过一个栈的转换到底有多少种出栈的序列。这个我们根据前边的结论就可以知道这个就是卡特兰数简单的使用。但是由于数据量比较大,使用JAVA即可。 代码如下: import java.math.BigInteger; import java.util.*; import java.math.*; public class Main { static ...

YG爱木木 440

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU 1023 Train Problem II Catalan数(卡特兰数)

HDU 1023 Train Problem II Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7876    Accepted Submission(s): 4223 Probl

huatian5的博客 582

hdu2067和hdu1023 卡特兰数解法与大数处理

上次用DP将这首题给水过去了。因为这里N<=35. 现在我们来研究一下当N<100时的卡特数。通过资料我们可以发现, n=100时,卡特兰数长度也就才58; 所以对于普通的题目,我们开a[110][110],足够的了。我们先打表后计算。不过要注意的是,最后的结果是卡特兰数的2倍。 这道题既然是高精度,那肯定就要使用高精度的算法啦。#include <stdio.h> #include <

jmhIcoding 842

HDU 1023 大数卡特兰数

http://acm.hdu.edu.cn/showproblem.php?pid=1023 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 orde...

xiji333的博客 269

HDU 1023卡特兰数 模板题

卡特兰数相关知识:https://zh.wikipedia.org/wiki/%E5%8D%A1%E5%A1%94%E5%85%B0%E6%95%B0 或:http://blog.csdn.net/nishadiaoma/article/details/52242998 Problem DescriptionAs we all know the Train Problem I, the boss

492

HDU1023(卡特兰数)

题意: 给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能。 解题思路: 模拟栈的问题而已。 这道题其实也是组合数学卡特兰数的一个典型应用而已。下面就介绍一下卡特兰数。 ======================================================================= 卡特兰数 卡特兰数又称卡塔兰数,是组合数学

ACM Dream 1227

HDU 1023 卡特兰数

//h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) ); #include //******************************* //打表卡特兰数 //第 n个 卡特兰数存在a[n]中,a[n][0]表示长度; //注意数是倒着存的,个位是 a[n][1] 输出时注意倒过来。 //*********************************

vsooda的专栏 2178

ACM-卡特兰数之Train Problem II——hdu1023

ACM 卡特兰数 Train Problem II hdu1023 大数乘法(存五位数)

继续激情,继续奋斗。 3122

hdu 1023 (卡特兰数)

点击打开链接 很有用的东西 令h(0)=1,h(1)=1,catalan数满足递推式 h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2) 例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2 h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5 另类

hello_fei 1166

卡特兰数专栏(HDU1023,HDU4165)

https://www.cnblogs.com/kuangbin/archive/2012/03/21/2410516.html 卡特兰数总结 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。 卡特兰数 前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 42...

qq_41713240的博客 364
上一篇: HDU2066 一个人的旅行 (priority_queue)
下一篇: HDU 1166 敌兵布阵 (小白的线段树)
jovie Hung
博客等级 码龄7年 19粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值