hdu 1023 hdu 1131
How Many Trees? |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 1105 Accepted Submission(s): 577 |
|
Problem Description
A binary search tree is a binary tree with root k such that any node v reachable from its left has label (v) <label (k) and any node w reachable from its right has label (w) > label (k). It is a search structure which can find a node with label x in O(n log
n) average time, where n is the size of the tree (number of vertices). Given a number n, can you tell how many different binary search trees may be constructed with a set of numbers of size n such that each element of the set will be associated to the label of exactly one node in a binary search tree? |
|
Input
The input will contain a number 1 <= i <= 100 per line representing the number of elements of the set.
|
|
Output
You have to print a line in the output for each entry with the answer to the previous question.
|
|
Sample Input
1 |
|
Sample Output
1 |
Train Problem II |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 730 Accepted Submission(s): 430 |
|
Problem Description
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 |
|
Sample Output
1 |
#include<iostream>
#include<cstdio>
#include<cstring>
int h[1001][1001];
int Catlan()
{
memset(h,0,sizeof(h));
h[1][0]=1;
h[1][1]=1;
h[2][0]=1;
h[2][1]=2;
for(int i=3;i<=101;i++)
{
int len=h[i-1][0];
for(int j=1;j<=len;j++)
{
h[i][j]+=h[i-1][j]*(4*i-2);
if(h[i][j]>=10)
{
h[i][j+1]+=h[i][j]/10;
h[i][j]%=10;
}
}
len=h[i][len+1]==0?len:len+1;
while(h[i][len]>=10)
{
h[i][1+len]=h[i][len]/10;
h[i][len]%=10;
len++;
}
int yu=0;
for(int k=len;k>=1;k--)
{
int temp=(h[i][k]+yu*10)/(i+1);
yu=(h[i][k]+yu*10)%(i+1);
h[i][k]=temp;
}
while(!h[i][len])
len--;
h[i][0]=len;
}
}
int main()
{
int n;
Catlan();
while(~scanf("%d",&n))
{
for(int i=h[n][0];i>=1;i--)
printf("%d",h[n][i]);
printf("\n");
}
return 0;
}
/******两个典型的卡塔兰数模板题(模板到代码都可以一样),火车那个的话以0表示出栈,1表示进栈,就看得出来了,二叉树的话,假设N个节点,根节点必须要有一个,接下来,可以左边0个,右边n-1个或左边1个,右边N-1个
或,,,,左边N-1个,右边0个,也看得出来是卡塔兰
万圣节之夜脱单的同学都和女票出去了,还在刷题,,Orz
不过刷题的感觉还是蛮不错的,哈哈,喜欢这种运动+刷题+和朋友在一起+泡图书馆的感觉!!
hdu 1023 hdu 1131的更多相关文章
- HDU 1023 Catalan数+高精度
链接:HDU 1023 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:5 ...
- HDU - 2222,HDU - 2896,HDU - 3065,ZOJ - 3430 AC自动机求文本串和模式串信息(模板题)
最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是 ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- hdu 1023 卡特兰数《 大数》java
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——1023 Train Problem II
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1023 Traning Problem (2) 高精度卡特兰数
Train Problem II Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Sub ...
- hdu 1023 卡特兰数+高精度
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
- hdu 1023(java实现进度计算)
题意:就是问你火车出战的方案数. 分析:卡特兰数的模板题,递推公式:a[n]=a[n-1]*(4*n-2)/(n+1). java代码实现: import java.util.*; import ja ...
随机推荐
- PHP学习之PHP trait解析
自PHP5.4.0起,PHP实现了一种代码复用的方法,称为trait. 众所周知,PHP中是单继承的,trait是为类似PHP的单继承语言而准备得一种代码复用机制.trait为了减少单继承语言的限制, ...
- composer在windows下安装并且设置全局变量
Composer是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件. 1丶使用安 ...
- 实现文件上下文管理(__enter__和___exit__)
实现文件上下文管理(__enter__和__exit__) 我们知道在操作文件对象的时候可以这么写 with open('a.txt') as f: '代码块' 上述叫做上下文管理协议,即with语句 ...
- Microsoft SQL Server 2008 R2 Express and Management Studio Express
https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads Microsoft SQL Server 2008 R2 RTM - E ...
- 如何给Swagger加注释
在Startup.cs文件中的ConfigureServices()方法中添加如下代码即可 services.AddSwaggerGen(options => { options.Swagger ...
- Activiti使用总结
工作流在我们日常的工作中用得可谓相当普及,尤其在企业内部管理系统,如考勤.财务.合同等系统中更是离不开它.在我们金融科技领域,工作流主要用于贷款审批.风控审核等环节.早期工作流在企业信息化发挥着很重要 ...
- easyUi的组合表格
公司之前的项目是用easyui写的里面还混搭着php...把分支下来,有点蒙.晚上回来恶补一下吧,今天渲染这个表格,我开始自己写假数据,然后用ajax操作再使用 obj.datagrid('loadD ...
- 三、DQL语言
目录 一.基础查询 (一)语法 (二)特点 (三)示例 二.条件查询 (一)语法 (二)筛选条件的分类 三.排序查询 (一)语法 (二)特点 四.常见函数 (一)介绍 (二)分类 五.单行函数 (一) ...
- python实现数据的压缩与归档
楔子 尽管现代计算机系统的存储能力日益增长,但生成数据的增长是永无休止的. 无损(lossless)压缩算法以压缩或解压缩数据花费的时间来换取存储数据所需要的空间,以弥补存储能力的不足. Python ...
- 认识和学习bash
认识Bash这个Shell 查看linux下shells: [shichaogeng@study etc]$ vim /etc/shells 查看登入时取得到的shell: [shichaogeng@ ...