hdu 3723 卡特兰数
来源:互联网 发布:阿里云系统盘满了 编辑:程序博客网 时间:2024/05/17 02:39
Delta Wave
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 690 Accepted Submission(s): 223
Problem Description
A delta wave is a high amplitude brain wave in humans with a frequency of 1 – 4 hertz which can be recorded with an electroencephalogram (EEG) and is usually associated with slow-wave sleep (SWS).
-- from Wikipedia
The researchers have discovered a new kind of species called "otaku", whose brain waves are rather strange. The delta wave of an otaku's brain can be approximated by a polygonal line in the 2D coordinate system. The line is a route from point (0, 0) to (N, 0), and it is allowed to move only to the right (up, down or straight) at every step. And during the whole moving, it is not allowed to dip below the y = 0 axis.
For example, there are the 9 kinds of delta waves for N = 4:
Given N, you are requested to find out how many kinds of different delta waves of otaku.
-- from Wikipedia
The researchers have discovered a new kind of species called "otaku", whose brain waves are rather strange. The delta wave of an otaku's brain can be approximated by a polygonal line in the 2D coordinate system. The line is a route from point (0, 0) to (N, 0), and it is allowed to move only to the right (up, down or straight) at every step. And during the whole moving, it is not allowed to dip below the y = 0 axis.
For example, there are the 9 kinds of delta waves for N = 4:
Given N, you are requested to find out how many kinds of different delta waves of otaku.
Input
There are no more than 20 test cases. There is only one line for each case, containing an integer N (2 < N <= 10000)
Output
Output one line for each test case. For the answer may be quite huge, you need only output the answer module 10100.
Sample Input
34
Sample Output
49
Source
2010 Asia Tianjin Regional Contest
卡塔兰数。c[n] = 2n! / ((n+1)! n!) = c(2n, n) / (n + 1)
因为始点与终点是水平的。 所以向上多少,向下就要多少,其余的都是水平前景的。
假设 上升了 k 次 那就必须下降 k 次 所以 a[k] = c(n, 2k) * c(2k, k) / (k + 1);
k 是从 0 变化到 n / 2的;
那么sum[n] = a[0] + a[1] + a[2] + ……+ a[k] (k <= n/2); 且a[0] = 1;(只有一个水平的).
但是如果对于每个 a[k] 都用阶乘是会超时的。
所以用数列公司 a[k] = c(n, 2k) * c(2k, k) / (k + 1) 与 a[k - 1] = c(n, 2k - 2) * c(2k - 2, k - 1) / k
递推出
a[k] = a[k-1] * (n - 2 * k + 1) * (n - 2 * k + 2) / (k * (k + 1));
由于数据比较大,所以采用java实现比较方便。
代码:
import java.util.*;import java.math.*;import java.io.*;public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); BigInteger sum,t; while (input.hasNext()) { int n = input.nextInt(); sum = t = BigInteger.ONE; for (int k = 1; k <= n / 2; k++) { t = t.multiply(BigInteger.valueOf((n - 2 * k + 1) * (n - 2 * k + 2))).divide(BigInteger.valueOf(k * (k + 1))); sum = sum.add(t); } System.out.println(sum.mod(BigInteger.TEN.pow(100))); } }}
0 0
- HDU 3723卡特兰数
- hdu 3723 卡特兰数
- HDU 1023 卡特兰数
- HDU 1133 卡特兰数
- hdu 5184 卡特兰数
- hdu 1023 卡特兰数
- HDU 4828 (卡特兰数)
- hdu 1023 卡特兰数
- 卡特兰数 hdu 5673
- 卡特兰数 Catalan数 hdu 1023
- hdu 1130 卡特兰数加大数
- HDU 3723 Delta Wave(组合计数,卡特兰数)
- hdu 3723 Delta Wave(卡特兰数)
- LA 5092 && hdu 3723 Delta Wave (卡特兰数)
- HDU 3723 Delta Wave(卡特兰数+大数)
- HDU-3723 Delta Wave(卡特兰数+大数递推)
- hdu 1023,catalan,卡特兰数
- hdu 1134 卡特兰数+大数
- 阿里收购高德 老虎宝典何去何从
- jsp验证码两个实例
- C++类中定义数据成员的类型的几种方式
- 高通面临10亿美元反垄断罚单:总裁急赴发改委
- 企业建网站 推广尤为重要
- hdu 3723 卡特兰数
- windows内核情景分析 --- Mdl
- HDU 2371 Decode the Strings 矩阵快速幂求m次置换
- 再谈“我是怎么招聘程序员的”
- GitHub入门:如何上传与下载工程?
- cocos2d-html5学习之三-为sprite添加触摸事件
- windows 内核情景分析 --- 网络通信
- 【Linux2.6内核模块编程实例指导】内核模块编程之入门(二)必备知识
- ubuntu安装blocklocks与简单的设置方法