博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1133 Buy the Ticket(Catalan)
阅读量:7155 次
发布时间:2019-06-29

本文共 2694 字,大约阅读时间需要 8 分钟。

 

Buy the Ticket

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

Total Submission(s): 5651    Accepted Submission(s): 2357

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

 

 

题意:

m個人拿50n個人拿100,而且售票处没有零钱。求这排人最终能够能全买到票的方案数

(如果没有50零钱找给拿一百的人则停)。

思路:

排列的所有可能情况:C(n+m,m)

假设一个数列 0110010当买到第三个人的时候便停止了,将后面的数1->0,0->1便能得到 0111101

反之亦然,于是我们可以得出他们是一一对应的。

于是我们用所有可能减去不成立的

(C(n+m,m) - C(n+m,m+1))*m!*n! = (n+m)! * (m-n+1) / (m+1); 

然后再利用JAVA的大整数即可 

import java.math.BigInteger;import java.util.Scanner;public class Main {	static BigInteger []F =  new BigInteger[105];	static BigInteger []A =  new BigInteger[205];	public static void ini()	{		F[1] = BigInteger.valueOf(1);		A[1] = BigInteger.valueOf(1);		A[0] = BigInteger.valueOf(0);		F[0] = F[1];		for(int i = 2;i < 105;i++)		{			F[i] = F[i-1].multiply(BigInteger.valueOf(i*4-2)).divide(BigInteger.valueOf(i+1));		}		for(int i = 2;i <= 203;i++)		{			A[i] = A[i-1].multiply(BigInteger.valueOf(i));		}	}	public static void main(String[] args) {		// TODO 自动生成的方法存根		ini();		Scanner Reader = new Scanner(System.in);		int x,y;		int cas = 1;		BigInteger ans;		while(true)		{			x = Reader.nextInt();			y = Reader.nextInt();						if(x == 0 && y == 0)				break;			System.out.println("Test #"+cas+":");			cas++;			if(x < y){				System.out.println("0");			}			else			{			  int t = x+y;			  ans = A[t].multiply(BigInteger.valueOf(x-y+1)).divide(BigInteger.valueOf(x+1));						  System.out.println(ans);			}		}     	}}

  

转载于:https://www.cnblogs.com/Przz/p/5409660.html

你可能感兴趣的文章
GPIO推挽输出和开漏输出详解
查看>>
事务处理和并发控制
查看>>
I18N、L10N、G11N
查看>>
引用类中的enum
查看>>
【转】Android开源项目发现---ListView篇(持续更新)
查看>>
利用锚点制作简单索引效果
查看>>
影响网站打开速度的9大因素
查看>>
HTML5之废弃和更新的元素与属性
查看>>
[转]asp.net解决高并发的方案.
查看>>
(转)unity中基于alpha通道的shadow volume实现
查看>>
linux下svn的co如何排除目录
查看>>
项目中最常用到的颜色
查看>>
[转]10个学习Android开发的网站推荐
查看>>
【linux驱动分析】之dm9000驱动分析(六):dm9000_init和dm9000_probe的实现
查看>>
交大人在各行各业一直不懈追逐着自己的创业梦想,如携程网、
查看>>
SGU 538. Emoticons 水题
查看>>
.net mvc4 利用 kindeditor 上传本地图片
查看>>
Note:This element neither has attached source nor attached Javadoc
查看>>
android 逆向project smail 语法学习
查看>>
CI框架 -- 开发环境、生产环境
查看>>