hdu
来源:互联网 发布:telnet本机端口不通 编辑:程序博客网 时间:2024/05/17 08:12
点击打开题目链接
How Many Trees?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2828 Accepted Submission(s): 1657
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?
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
123
Sample Output
125
第一次用Java写大数,感觉超简单~~~
代码:
import java.math.*;import java.util.*;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Integer n,N=102,i; BigInteger []f=new BigInteger[N]; f[1]=BigInteger.valueOf(1); for(i=2;i<N;i++) f[i]=f[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1)); Scanner cin=new Scanner(System.in); while(cin.hasNext()) { n=cin.nextInt(); System.out.println(f[n]); } cin.close(); }}
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- SAE storage linux管理
- linux c dynamic library programming
- 7/31
- matlab中m文件输出为c文件的方法
- hdu-2091-空心三角形
- hdu
- 计算机网络笔试面试题目大全
- HDU 4902 Nice boat
- JAVA IO 同步与异步、阻塞与非阻塞
- HDU 1896 stone
- Mplayer 音量控制
- 线性DP 四边形不等式优化 hdu3506
- 使用adb查看数据库的一些命令
- Java IO相关