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 ...
随机推荐
- docker 入门2 - 容器 【翻译】
入门,第 2 部分:容器 先决条件 安装的 Docker 版本是 1.13 及以上. 读完 第一部分 用下面的命令快速测试你的环境是否完备: docker run hello-world 概述 现在开 ...
- vue中的键盘事件
@keydown(键盘按下时触发),@keypress(键盘按住时触发),@keyup(键盘弹起) 获取按键的键码 e.keyCode @keyup.13 按回车键 @keyup.enter ...
- VBA学习资料分享-3
VBA创建/发送OUTLOOK邮件时怎么加上默认签名呢?用过OUTLOOK写邮件的人都知道,如果你设置了默认签名,那么在创建空白邮件的时候就会自动加上你设置的签名.根据这一特性,我们可以在用VBA创建 ...
- CNN 笔记
1. 卷积后的图像的大小为 (w+2p-f)*3 / s W为图像的宽,p为padding的大小, f为卷积核大小, 3 为图像的通道数, s为步长 2. 卷积层和池化层的区别? 卷积层是 ...
- 0基础学习web技术
说实话0基础学习前端挺难的,当然也没有是技术是容易学习的 我只是想分享一下我的学习经历: 分为以下几点: 1:学习html和css ,学习完成之后可以模仿各大网站的静态网页 2:学习原生js基础,jq ...
- 12.Show Profile
1.是什么: 是mysql提供可以用来分析当前会话中语句执行的资源消耗情况,可以用于SQL的调优的测量 show profile 查询SQL在MySQL服务器里面的执行细节和生命周期情况 2.默认情况 ...
- 阿里P8架构师总结Java并发面试题(精选)
一.什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成一 ...
- ie11浏览器不显示vbs脚本
最初接触学习vbs在浏览器上运行,老不显示vbscript脚本语言,所以找了很久,最后就用这个方法吧,比较简单有效 原因:新版IE不再支持 VBScript,就是因为微软已经放弃把VBScript作为 ...
- xcode 中 vary for traits详解
https://www.jianshu.com/p/d6896437e5a7 这篇文章写的很好!
- oracle 初试 hint
最近在研究oracle的视图问题,本来想全转成 物化视图(materialized view)的,这样可以极大提升系统的响应时间,无奈工作量太大,所以就研究了SQL优化的问题. 我这个普通视图 有36 ...