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. 【SQL Sever】实现SQL Sever的发布。订阅。 双机热备

    实现SQL Sever的发布和订阅  最大的好处就是: 可以实现读写分离,增删改操作在主数据库服务器上进行,查询在备份数据库服务器上进行.一方面提高软件执行效率,另一方面也减轻主库压力. 本次实现发布 ...

  2. 【MySQL 安装过程2】MySQL安装到 最后一部 未响应 的解决方案

    首先我们应该做的 是在控制面板将MySQL 卸载.再进行以下的操作: 1.在开始菜单下,点击运行,输入regedit,进入注册表编辑器目录下 2.在注册表编辑器里system下找到controlset ...

  3. 防止ViewPager和Fragment结合使用时候的数据预加载

    不知道你们使用ViewPager和Fragment结合的时候发现一个问题没,如果你的每个Fragment都需要请求网络数据,并且你在请求网络数据的时候会加入进度对话框的加载显示效果,当你显示第一个Fr ...

  4. 通过maven下载jar包

    准备 你得先安装Maven如果不会点击后面的连接查看一二步.http://www.cnblogs.com/luoruiyuan/p/5776558.html 1.在任意目录下创建一个文件夹,其下创建一 ...

  5. MySql数据库安装&修改密码&开启远程连接图解

    相关工具下载地址: mysql5.6 链接:http://pan.baidu.com/s/1o8ybn4I密码:aim1 SQLyog-12.0.8 链接:http://pan.baidu.com/s ...

  6. 在C#程序中实现插件架构

    阅读提示:这篇文章将讲述如何利用C#奇妙的特性,实现插件架构,用插件(plug-ins)机制建立可扩展的解决方案. 在.NET框架下的C#语言,和其他.NET语言一样提供了很多强大的特性和机制.其中一 ...

  7. CSS3 calc()的使用

    前言: 平时在制作页面的时候,总会碰到有的元素是100%的宽度.众所周知,如果元素宽度为100%时,其自身不带其他盒模型属性设置还好,要是有别的,那将导致盒子撑破.比如说,有一个边框,或者说有marg ...

  8. SpringJDBC解析1-使用示例

    JDBC(Java Data Base Connectivity,Java数据库连接)是一种用于执行SQL语句的JavaAPI,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组 ...

  9. css3 -- 多列

    1.指定分列: E{column-count:2:} --- 两列 E{ -moz-column-count:2: -webkit-column-count:2: } Firefox与webkit实现 ...

  10. xampp的Apache无法启动解决方法

    XAMPP Apache 无法启动原因1(缺少VC运行库): 这个就是我遇到的问题原因,下载安装的XAMPP版本是xampp-win32-1.7.7-VC9,而现有的Windows XP系统又没有安装 ...