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. ObCallback回调钩子检测

    ObCallback回调钩子检测 2013-12-20 Nie.Meining Ring0 在 PatchGuard 的摧残下,通过 ObRegisterCallbacks 函数注册回调钩子已经成了 ...

  2. QQ互联登录 微博登录问题

    qq 需要用开放平台的扣扣测试 审核通过后 开放所有用户 微博 出现获取token  个人信息失败  需要在微博里添加测试账号  审核通过后 开放所有用户

  3. 智能车学习(十)——MMA8451加速度计的使用

    一.驱动说明: 就是使用I2C的通信方式驱动这款加速度计就行了,代码的话选择使用51单片机的代码进行移植. 二.代码分享: 1.头文件: #ifndef MMA8451_H #define MMA84 ...

  4. Linux学习笔记(20) Linux系统管理

    1.进程管理 进程是正在执行的一个程序或命令,每一个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. 进程管理的作用有判断服务器健康状态.查看系统中所有进程及杀死进程.一般都可以采用 ...

  5. 自己yy的Splay

    #include <iostream> #include <cstdio> #include <queue> using namespace std; ; stru ...

  6. 第一个vs2013控制台程序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. python装饰器--@property

    @property 考察 Student 类: class Student(object): def __init__(self, name, score): self.name = name sel ...

  8. HDU 4858 项目管理 分块

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4858 题解: 下面说一个插入查询时间复杂度为sqrt(m)的算法: 对每个点定义两个值:val,su ...

  9. JS(获得当前时间并且用2015-01-01格式表示)

    一个简单的小例子,实现获得当前时间,js代码如下: function getdate() {var date = new Date();var mon = date.getMonth()  + 1;  ...

  10. Git Commands

    Show ssh key file: ssh -v git@github.com