HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)
题目链接:https://cn.vjudge.net/problem/HDU-1023
题意
卡特兰数的应用之一
求一个长度为n的序列通过栈后的结果序列有几种
思路
一开始不知道什么是卡特兰数,猜测是一个递推题
注意到在序列第i个元素入栈时,前几个元素都进过栈,就是通过栈的操作
设n个元素通过栈的结果序列个数为h[n],则有:
\]
查了以后发现这是卡特兰数的规律,有通项:
\]
考虑到又要写高精度算法,想写python,发现没有python,只能先学一下java好了...
代码
// Main.java
import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner cin=new Scanner(System.in);
BigInteger[] num=new BigInteger[100+5];
num[1]=new BigInteger("1");
for (int i=2; i<=100; i++){
Integer tmp1=4*i-2, tmp2=i+1;
BigInteger a=new BigInteger(tmp1.toString());
BigInteger b=new BigInteger(tmp2.toString());
num[i]=num[i-1].multiply(a).divide(b);
}
while (cin.hasNext()){
int n=cin.nextInt();
System.out.println(num[n]);
}
}
}
| Time | Memory | Length | Lang | Submitted |
|---|---|---|---|---|
| 202ms | 9892kB | 632 | Java | 2018-02-09 19:18:25 |
HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)的更多相关文章
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
- HDOJ 1023 Train Problem II 卡特兰数
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- HDU 1023 Train Problem II( 大数卡特兰 )
链接:传送门 题意:裸卡特兰数,但是必须用大数做 balabala:上交高精度模板题,增加一下熟悉度 /************************************************ ...
- C - Train Problem II——卡特兰数
题目链接_HDU-1023 题目 As we all know the Train Problem I, the boss of the Ignatius Train Station want to ...
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
- 1023 Train Problem II(卡特兰数)
Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...
随机推荐
- 计算sigma
1.计算平均值Avg Avg = (a0 + a1 + ......+ an-1) / n 2.计算sigma sigma = sqrt( ( (a0-avg) ^2 + (a1-avg) ^2 ...
- android实现自动安装
安装: String str = "/CanavaCancel.apk"; String fileName = Environment.getExternalStorageDire ...
- calender怎么获取每周的周日(给每周的周日特定时间点设置定时)
获取每周的周日 //如果是周日,特殊处理.老外的周日-周六为一周 calendarTemp.add(Calendar.WEEK_OF_MONTH,1); calendarTemp.set(Calend ...
- Codeforces 986A. Fair(对物品bfs暴力求解)
解题思路: 1.对物品i bfs,更新每个小镇j获得每个物品i的最短距离. 2.时间复杂度o(n*k),满足2s的要求. 代码: #include <iostream> #include ...
- Servlet学习(七)——cookie
一.会话技术简介 1.存储客户端的状态 例如网站的购物系统,用户将购买的商品信息存储到哪里?因为Http协议是无状态的,也就是说每个客户访问服务器端资源时,服务器并不知道该客户端是谁,所以需要会话技术 ...
- HttpWebRequest WebExcepton: The remote server returned an error: (407) Proxy Authentication Required.
1. Supply the credentials of the Currently Logged on User to the Proxy object similar to this: // Be ...
- java中class,public的用法
java中class,public的用法 一.Java访问权限饰词(access specifiers) Java有public.protect.friendly.private四种访问权限,并且这四 ...
- CentOS 7在grub rescue模式中修复系统
安装完CentOS 7后 修改硬盘分区后,系统重启后,无法正常启动,进入grub rescue模式: 网上大多数centos grub rescue的资料应该是Centos 7之前的,其中提到的命令很 ...
- How Javascript works (Javascript工作原理) (九) 网页消息推送通知机制
个人总结: 1.介绍了网页消息推送通知机制 全文地址:https://github.com/Troland/how-javascript-works 这是 JavaScript 工作原理的第九章. 现 ...
- JavaScript函数写法整理
1.普通函数定义的两种写法 function hello(){ console.log("hello!"); } var hello = function(){ console.l ...