Game of Connections

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4246    Accepted Submission(s): 2467

Problem Description
This
is a small but ancient game. You are supposed to write down the numbers
1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the
ground to form a circle, and then, to draw some straight line segments
to connect them into number pairs. Every number must be connected to
exactly one another. And, no two segments are allowed to intersect.

It's
still a simple game, isn't it? But after you've written down the 2n
numbers, can you tell me in how many different ways can you connect the
numbers into pairs? Life is harder, right?

 
Input
Each
line of the input file will be a single positive number n, except the
last line, which is a number -1. You may assume that 1 <= n <=
100.
 
Output
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.
 
Sample Input
2
3
-1
 
Sample Output
2
5
 
Source
题意:
2n个数顺时针组成环,用一条线将两个相连,并且每个数只能与另外一个数相连,连线不能相交,问有几种不同的连线方案。
代码:
又是那个神奇的递推公式。
 package luzhiyuan;
import java.util.Scanner;
import java.math.BigInteger;
public class java1 {
public static void main(String[] args){
BigInteger [][]a=new BigInteger[102][102];
BigInteger sta=BigInteger.valueOf(1); //把其他形式的数化为大整数
BigInteger zeo=BigInteger.valueOf(0);
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
a[i][j]=zeo; //如果想让后面的加法函数可用一定要给大整数赋初值
for(int i=1;i<=100;i++)
a[i][0]=sta;
for(int i=1;i<=100;i++)
for(int j=1;j<=i;j++){
a[i][j]=a[i][j].add(a[i-1][j]);
a[i][j]=a[i][j].add(a[i][j-1]);
}
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
int n=cin.nextInt();
if(n==-1) break;
System.out.println(a[n][n]);
}
}
}

Buy the Ticket

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6361    Accepted Submission(s): 2661

Problem Description
The
"Harry Potter and the Goblet of Fire" will be on show in the next few
days. As a crazy fan of Harry Potter, you will go to the cinema and have
the first sight, won’t you?

Suppose the cinema only has one
ticket-office and the price for per-ticket is 50 dollars. The queue for
buying the tickets is consisted of m + n persons (m persons each only
has the 50-dollar bill and n persons each only has the 100-dollar bill).

Now
the problem for you is to calculate the number of different ways of the
queue that the buying process won't be stopped from the first person
till the last person.
Note: initially the ticket-office has no money.

The
buying process will be stopped on the occasion that the ticket-office
has no 50-dollar bill but the first person of the queue only has the
100-dollar bill.

 
Input
The
input file contains several test cases. Each test case is made up of
two integer numbers: m and n. It is terminated by m = n = 0. Otherwise,
m, n <=100.
 
Output
For
each test case, first print the test number (counting from 1) in one
line, then output the number of different ways in another line.
 
Sample Input
3 0
3 1
3 3
0 0
 
Sample Output
Test #1:
6
Test #2:
18
Test #3:
180
 
Author
HUANG, Ninghai
题意:
一群人排队买票,票价50元,有人拿着50元的,有人拿着100元的,售票员没有钱,问怎样排队才能让每个人都买到票,有多少种排队方案。
依然是那个递推公式,50元的人要永远多于100元的人,50元的人作为列,100元的人作为行,一个上三角方格阵,每个人的位置又有A(n,n)*A(m,m)种,再乘a[n][m].
代码:

 package luzhiyuan;
import java.util.Scanner;
import java.math.BigInteger;
public class java1 {
public static void main(String[] args){
BigInteger [][]a=new BigInteger[102][102];
BigInteger sta=BigInteger.valueOf(1); //把其他形式的数化为大整数
BigInteger zeo=BigInteger.valueOf(0);
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
a[i][j]=zeo; //如果想让后面的加法函数可用一定要给大整数赋初值
for(int i=1;i<=100;i++)
a[i][0]=sta;
for(int i=1;i<=100;i++)
for(int j=1;j<=i;j++){
a[i][j]=a[i][j].add(a[i-1][j]);
a[i][j]=a[i][j].add(a[i][j-1]);
}
Scanner cin=new Scanner(System.in);
int t=0;
while(cin.hasNext()){
int n=cin.nextInt();
int m=cin.nextInt();
int nn=n,mm=m;
if(n==0&&m==0) break;
t++;
BigInteger x=BigInteger.valueOf(n);
BigInteger y=BigInteger.valueOf(m);
BigInteger ans=BigInteger.valueOf(1);
while(nn>1){
ans=ans.multiply(x);
nn--;
x=x.subtract(sta);
}
while(mm>1){
ans=ans.multiply(y);
mm--;
y=y.subtract(sta);
}
ans=ans.multiply(a[n][m]);
System.out.println("Test #"+t+":");
System.out.println(ans);
}
}
}

HDU1134/HDU1133 递推 大数 java的更多相关文章

  1. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  2. Tiling(递推+大数)

    Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...

  3. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  4. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

  5. ACM学习历程—HDU1023 Train Problem II(递推 && 大数)

    Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know  ...

  6. Tiling 简单递推+大数

    Tiling c[0]=1,c[1]=1,c[2]=3;   c[n]=c[n-1]+c[n-2]*2;   0<=n<=250.   大数加法 java  time  :313ms 1 ...

  7. poj 2506 Tiling(递推 大数)

    题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...

  8. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  9. hdu 1041(递推,大数)

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

随机推荐

  1. 及其简短的Splay代码

    #include <stdio.h> #include <queue> #include <algorithm> #include <stdlib.h> ...

  2. 解决mysql shell执行中文表名报command not found错误

    mysql -h 192.168.22.201 -uusername -ppassword --default-character-set=utf8 rom3 -e "DELETE FROM ...

  3. 使用jQuery要注意的问题

    1. $.find()与$.children()的区别 有如下HTML片段: 复制代码代码如下: <div id="div_four"> <input id=&q ...

  4. Python与Hack之Unix口令

    1.在实验时候,先导入crypt库:必须在Unix环境下才能实现这个模块 2.代码贴一下,以后有了Unix环境试试吧: import cryptimport syssys.modules['Crypt ...

  5. 《DSP using MATLAB》示例Example4.8

    代码: b = [0,1]; a = [3, -4, 1]; % polynomials coefficients [R,p,c] = residuez(b,a) [b,a] = residuez(R ...

  6. Codeforce 546D

    Soldier and Number Game Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. wpf ListBox,item两列不等高。

    业务有这样的需求,类似瀑布流.内容两列不等高展示. 只需要继承panel,重写MeasureOverride和ArrangeOverride方法就行了. 很简单,内容都在代码里. using Syst ...

  8. WPF:依赖属性的数据绑定

    One of the strengths of WPF is its data binding capabilities. Although data binding is not new (in f ...

  9. 优化WPF 3D性能

    Maximize WPF 3D Performance .NET Framework 4.5   As you use the Windows Presentation Foundation (WPF ...

  10. ccc pool

    var sp = new _ccsg.Sprite("a.png"); this.addChild(sp); cc.pool.putInPool(sp); cc.pool.getF ...