Buy the Ticket

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

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
 
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1715 1207 1865 1284 1753 
 

简单题。推出递推公式就差不多了。

 //0 MS    324 KB    Visual C++
/* 递推公式:
ans[n][m]=(n+m)!*(n-m+1)/(n+1);
*/
#include<stdio.h>
#include<string.h>
#define N 10000
int f[][]={};
void mul(int a[],int n)
{
int temp=;
for(int i=;i<;i++){
temp+=n*a[i];
a[i]=temp%N;
temp/=N;
}
}
void div(int a[],int n)
{
int temp=;
for(int i=;i>=;i--){
temp=temp*N+a[i];
a[i]=temp/n;
temp%=n;
}
}
void init()
{
f[][]=;
for(int i=;i<=;i++){
memcpy(f[i],f[i-],*sizeof(int));
mul(f[i],i);
}
}
int main(void)
{
int n,m,k=;
init();
while(scanf("%d%d",&n,&m),n+m)
{
printf("Test #%d:\n",k++);
if(m>n){
puts("");continue;
}
int ans[];
memcpy(ans,f[n+m],*sizeof(int));
mul(ans,n-m+);
div(ans,n+); int i=;
for(;!ans[i];i--);
printf("%d",ans[i]);
while(i--) printf("%04d",ans[i]);
printf("\n");
}
return ;
}

hdu 1133 Buy the Ticket (大数+递推)的更多相关文章

  1. HDU 1133 Buy the Ticket (数学、大数阶乘)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. hdu 1133 Buy the Ticket(Catalan)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. HDU——1133 Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  5. hdu 1133 Buy the Ticket

    首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...

  6. HDU 1133 Buy the Ticket 卡特兰数

    设50元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java ...

  7. HDU 1297 Children’s Queue (递推、大数相加)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU-1041-Computer Transformation,大数递推,水过~~

                                                                                  Computer Transformatio ...

  9. hdu 5335 Walk Out(bfs+斜行递推) 2015 Multi-University Training Contest 4

    题意—— 一个n*m的地图,从左上角走到右下角. 这个地图是一个01串,要求我们行走的路径形成的01串最小. 注意,串中最左端的0全部可以忽略,除非是一个0串,此时输出0. 例: 3 3 001 11 ...

随机推荐

  1. python的列表数据类型及常用操作

    列表是最常用的Python数据类型,它可以作为一个方括号内的逗号分隔值出现. 列表中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. 列表可以进行的操作包括索 ...

  2. 操作BOM

    BOM的作用是将相关的元素组织包装起来,提供给程序设计人员使用,从而降低开发人员的劳动量,提高设计Web页面的能力. 整个window对象是整个BOM的核心. 通过BOM可实现的功能: 弹出新的浏览器 ...

  3. hive 学习系列三(表格的创建create-table)

    表格创建: 语法 第一种建表的形式: 说明: temporary 临时表,在当前回话内,这张表有效,当回话结束,可以理解为程序结束,则程序终止. external 外部表, hdfs 上的表的文件,并 ...

  4. 析构函数的调用与return语句

    老师在课堂上讲到了return语句在执行时会自动调用对象的析构函数.我编写了下述代码测试发现整个程序析构函数调用次数与构造函数不等,这样难道不会产生内存泄漏吗? 源代码如下: #include < ...

  5. SQL数据库 面试题

    一.sql理论题 1.触发器的作用? 答:触发器是一中特殊的存储过程,主要是通过事件来触发而被执行的.它可以强化约束,来维护数据的完整性和一致性,可以跟踪数据库内的操作从而不允许未经许可的更新和变化. ...

  6. Vue 去脚手架

    上回模仿了一个nw,按照原理说,简单. 今天说Vue,脚手架是个好东西,做项目都给你配置好,不过对于我这种只想做一个界面的人来说,有点儿太大了,用不上. 如果说,不用脚手架要面临哪些问题呢. 1. 组 ...

  7. allegro导入网表过程中出现的错误信息

    1. 找不到焊盘PAD,下面这句话的意思是器件封装找不到焊盘46.pad WARNING(SPMHNI-): Unable to load symbol ): Could not find padst ...

  8. ActiveMQ测试实例

    ActiveMQ的安装与启动 1 下载ActiveMQ:http://activemq.apache.org/download.html 2 下载后解压到任意文件夹,解压后文件夹内的目录为: 3 进入 ...

  9. 【多线程】 Task ,async ,await

    [多线程]Task ,async ,await 一. WinForm 里经常会用到多线程, 多线程的好出就不多说了,来说说多线程比较麻烦的地方 1. UI 线程与其他线程的同步,主要是 Form 和 ...

  10. Unity5.6偶尔不能创建项目解决办法

    Unity5.6偶尔启动后,不能创建项目,解决办法如下: 1.打开Unity 2.在开始窗口退出当前登录的账户 3.重新登录 4.然后就可以创建新项目了 5.如果以上方法不生效,关闭Unity再重试一 ...