Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6517 Accepted Submission(s): 2720

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

f[i][j]表示有i个50j个100的方法数。当i<j时,f[i][j]=0。当i=j时,f[i][j]=f[i][j-1]。当i>j时,f[i][j]=f[i-1][j]+f[i][j-1]。

最后分别再乘上n和m的阶乘。

#include <iostream>
#include <string>
using namespace std;
#ifndef BIGNUM
#define BIGNUM
class BigNum {
#define MAXSIZEOFBIGNUM 500
#define BASE 10
#define DLEN 1
public:
int Len;
int d[MAXSIZEOFBIGNUM];
public:
BigNum(void);
BigNum(const int);
BigNum(const char *);
BigNum(const BigNum &);
BigNum & operator = (const BigNum &);
void clear(void);
friend istream& operator>>(istream&, BigNum&);
friend ostream& operator<<(ostream&, BigNum&);
bool operator == (const BigNum &) const;
bool operator > (const BigNum &) const;
bool operator < (const BigNum &) const;
bool operator >= (const BigNum &) const;
bool operator <= (const BigNum &) const;
BigNum operator + (const BigNum &) const;
BigNum operator - (const BigNum &) const;
BigNum operator * (const BigNum &) const;
BigNum operator / (const BigNum &) const;
BigNum operator % (const BigNum &) const;
void operator ++ (void);
void operator -- (void);
BigNum operator + (const int &) const;
BigNum operator - (const int &) const;
BigNum operator * (const int &) const;
BigNum operator / (const int &) const;
int operator % (const int &) const;
BigNum operator ^ (const int &) const;
~BigNum() {}
};
BigNum::BigNum() {
Len = ;
memset(d, , sizeof(d));
}
BigNum::BigNum(const int ops) {
int x = ops;
Len = ;
memset(d, , sizeof(d));
while(x) {
Len++;
d[Len] = x % BASE;
x /= BASE;
}
}
BigNum::BigNum(const char * ops) {
int L = strlen(ops) - , b = ;
memset(d, , sizeof(d));
while(ops[b] == '') {
b++;
}
Len = ;
while(L - b + >= DLEN) {
int x = ;
for(int i = L - DLEN + ; i <= L; i++) {
x = x * + ops[i] - '';
}
Len++;
d[Len] = x;
L -= DLEN;
}
int x = ;
for(int i = b; i <= L; i++) {
x = x * + ops[i] - '';
}
Len++;
d[Len] = x;
}
BigNum::BigNum(const BigNum &ops) : Len(ops.Len) {
memset(d, , sizeof(d));
for(int i = ; i <= Len; i++) {
d[i] = ops.d[i];
}
}
BigNum & BigNum::operator = (const BigNum &ops) {
memset(d, , sizeof(d));
Len = ops.Len;
for(int i = ; i <= Len; i++) {
d[i] = ops.d[i];
}
return *this;
}
void BigNum::clear(void) {
for(int i = ; i <= MAXSIZEOFBIGNUM - ; i++) {
if(d[i] < ) {
d[i] += BASE;
d[i + ]--;
}
if(d[i] >= BASE) {
d[i] -= BASE;
d[i + ]++;
}
}
for(int i = MAXSIZEOFBIGNUM - ; i >= ; i--)
if(d[i] > ) {
Len = i;
return;
}
Len = ;
}
istream& operator>>(istream &in, BigNum &ops) {
char str[MAXSIZEOFBIGNUM + ];
in >> str;
int L = strlen(str), b = ;
while(str[b] == '') {
b++;
}
ops.Len = ;
for(int i = L - ; i >= b; i--) {
ops.Len++;
ops.d[ops.Len] = str[i] - '';
}
return in;
}
ostream& operator<<(ostream& out, BigNum& ops) {
for(int i = ops.Len; i >= ; i--) {
out << ops.d[i];
}
if(ops.Len == ) {
out << "";
}
return out;
}
bool BigNum::operator == (const BigNum &ops) const {
if(Len != ops.Len) {
return false;
}
for(int i = Len; i >= ; i--)
if(d[i] != ops.d[i]) {
return false;
}
return true;
}
bool BigNum::operator > (const BigNum &ops) const {
if(Len < ops.Len) {
return false;
} else if(Len > ops.Len) {
return true;
} else {
for(int i = Len; i >= ; i--)
if(d[i] < ops.d[i]) {
return false;
} else if(d[i] > ops.d[i]) {
return true;
}
}
return false;
}
bool BigNum::operator < (const BigNum &ops) const {
if(Len < ops.Len) {
return true;
} else if(Len > ops.Len) {
return false;
} else {
for(int i = Len; i >= ; i--)
if(d[i] < ops.d[i]) {
return true;
} else if(d[i] > ops.d[i]) {
return false;
}
}
return false;
}
bool BigNum::operator >= (const BigNum &ops) const {
if(Len < ops.Len) {
return false;
} else if(Len > ops.Len) {
return true;
} else {
for(int i = Len; i >= ; i--)
if(d[i] < ops.d[i]) {
return false;
} else if(d[i] > ops.d[i]) {
return true;
}
}
return true;
}
bool BigNum::operator <= (const BigNum &ops) const {
if(Len < ops.Len) {
return true;
} else if(Len > ops.Len) {
return false;
} else {
for(int i = Len; i >= ; i--)
if(d[i] < ops.d[i]) {
return true;
} else if(d[i] > ops.d[i]) {
return false;
}
}
return true;
}
BigNum BigNum::operator + (const BigNum &ops) const {
BigNum ret(*this);
for(int i = ; i <= ops.Len; i++) {
ret.d[i] += ops.d[i];
}
ret.clear();
return ret;
}
BigNum BigNum::operator - (const BigNum &ops) const {
BigNum ret(*this);
for(int i = ops.Len; i >= ; i--) {
ret.d[i] -= ops.d[i];
}
ret.clear();
return ret;
}
BigNum BigNum::operator * (const BigNum &ops) const {
BigNum ret, now(*this);
for(int i = ; i <= now.Len; i++)
for(int j = ; j <= ops.Len; j++) {
ret.d[i + j - ] += now.d[i] * ops.d[j];
}
for(int i = ; i <= MAXSIZEOFBIGNUM - ; i++)
if(ret.d[i] >= BASE) {
ret.d[i + ] += ret.d[i] / BASE;
ret.d[i] %= BASE;
}
for(int i = MAXSIZEOFBIGNUM - ; i >= ; i--)
if(ret.d[i] > ) {
ret.Len = i;
break;
}
return ret;
}
BigNum BigNum::operator / (const BigNum &ops) const {
BigNum now = (*this), div, mod;
div.Len = now.Len;
mod.Len = ;
for(int j = now.Len; j >= ; j--) {
mod.Len++;
for(int p = mod.Len; p >= ; p--) {
mod.d[p] = mod.d[p - ];
}
mod.d[] = now.d[j];
while(mod >= ops) {
div.d[j]++;
mod = mod - ops;
}
if(mod.Len == && mod.d[] == ) {
mod.Len--;
}
}
div.clear();
mod.clear();
return div;
}
BigNum BigNum::operator % (const BigNum &ops) const {
BigNum now = (*this), div, mod;
div.Len = now.Len;
mod.Len = ;
for(int j = now.Len; j >= ; j--) {
mod.Len++;
for(int p = mod.Len; p >= ; p--) {
mod.d[p] = mod.d[p - ];
}
mod.d[] = now.d[j];
while(mod >= ops) {
div.d[j]++;
mod = mod - ops;
}
if(mod.Len == && mod.d[] == ) {
mod.Len--;
}
}
div.clear();
mod.clear();
return mod;
}
void BigNum::operator ++ (void) {
d[]++;
for(int i = ; i <= MAXSIZEOFBIGNUM - ; i++)
if(d[i] >= BASE) {
d[i] -= BASE;
d[i + ]++;
} else {
break;
}
if(d[Len + ] > ) {
Len++;
}
}
void BigNum::operator -- (void) {
d[]--;
for(int i = ; i <= MAXSIZEOFBIGNUM - ; i++)
if(d[i] < ) {
d[i] += BASE;
d[i + ]--;
} else {
break;
}
if(d[Len] == ) {
Len--;
}
}
BigNum BigNum::operator + (const int & ops) const {
BigNum ret = (*this);
ret.d[] += ops;
ret.clear();
return ret;
}
BigNum BigNum::operator - (const int & ops) const {
BigNum ret = (*this);
ret.d[] -= ops;
ret.clear();
return ret;
}
BigNum BigNum::operator * (const int & ops) const {
BigNum ret(*this);
for(int i = ; i <= ret.Len; i++) {
ret.d[i] *= ops;
}
for(int i = ; i <= MAXSIZEOFBIGNUM - ; i++)
if(ret.d[i] >= BASE) {
ret.d[i + ] += ret.d[i] / BASE;
ret.d[i] %= BASE;
}
for(int i = MAXSIZEOFBIGNUM - ; i >= ; i--)
if(ret.d[i] > ) {
ret.Len = i;
return ret;
}
ret.Len = ;
return ret;
}
BigNum BigNum::operator / (const int & ops) const {
BigNum ret;
int down = ;
for(int i = Len; i >= ; i--) {
ret.d[i] = (d[i] + down * BASE) / ops;
down = d[i] + down * BASE - ret.d[i] * ops;
}
ret.Len = Len;
while(ret.d[ret.Len] == && ret.Len > ) {
ret.Len--;
}
return ret;
}
int BigNum::operator % (const int &ops) const {
int mod = ;
for(int i = Len; i >= ; i--) {
mod = ((mod * BASE) % ops + d[i]) % ops;
}
return mod;
}
BigNum BigNum::operator ^ (const int &ops) const {
BigNum t, ret();
if(ops == ) {
return ret;
}
if(ops == ) {
return *this;
}
int m = ops, i;
while(m > ) {
t = *this;
for(i = ; (i << ) <= m; i <<= ) {
t = t * t;
}
m -= i;
ret = ret * t;
if(m == ) {
ret = ret * (*this);
}
}
return ret;
}
#endif
BigNum f[][];
int main() {
f[][] = ;
for(int i = ; i <= ; i++) {
for(int j = ; j <= i; j++) {
if(j == ) {
f[i][j] = ;
continue;
}
if(i == j) {
f[i][j] = f[i][j - ];
} else {
f[i][j] = f[i][j - ] + f[i - ][j];
}
}
}
int n, m,t=;
BigNum x;
while(scanf("%d%d", &n, &m) != EOF) {
t++;
if(n + m == ) {
break;
}
x = f[n][m];
for(int i = ; i <= n; i++) {
x = x * i;
}
for(int i = ; i <= m; i++) {
x = x * i;
}
cout << "Test #" << t << ":" << endl;
cout << x << endl;;
}
return ;
}

Buy the Ticket{HDU1133}的更多相关文章

  1. HDU1133 Buy the Ticket —— 卡特兰数

    题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  3. 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket

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

  4. Buy the Ticket(卡特兰数+递推高精度)

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

  5. hdu 1133 Buy the Ticket(Catalan)

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

  6. Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)

    题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...

  7. HDUOJ---1133(卡特兰数扩展)Buy the Ticket

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

  8. Codeforces 938.D Buy a Ticket

    D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. hdu 1133 Buy the Ticket (大数+递推)

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

随机推荐

  1. Ubuntu离线更新flashplugin

    当网络太烂时,Ubuntu更新可能会卡在下载flashplugin上面,继而出错.在U论坛上找到一篇帖子,寻到成功安装flashplugin-installer的方法: 1.首先使用sudo apt- ...

  2. Codeforces Round #304 C(Div. 2)(模拟)

    题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...

  3. AngularJS XMLHttpRequest $http服务

    $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据. 读取JSON文件 以下是存储在web服务器上的 JSON 文件: http://www.runoob.com/try/ ...

  4. 按键的使用(一)------verilog

    按键在项目中应用还是很频繁的,这里主要介绍按键的几种用法. 1.按下一次有效:按下一次计数器增加一下. 2.按下连续有效:按下不松,计数器就一直增加. 3.按下无效,松开有效:按下时计数器值不变,按键 ...

  5. SQLServer内置函数

    类型转换函数cast和convert --cast一般更容易使用,convert的优点是可以格式化日期和数值 select CAST('123.4' as int) --失败 select CONVE ...

  6. IIS7 经典模式和集成模式的区别(转载)

    转载地址:http://www.poluoluo.com/server/201301/193110.html 升级过程中出现了比较多的问题,前面文章也提到过几个.这次就主要介绍下httpHandler ...

  7. protobuf-net 对象二进制序列化与反序列号(转)

    概述: Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法.它比xml格式要少的多,甚至比二进制数据格式也小的多. Prot ...

  8. 【翻译三】java-并发之线程对象和实现

    Thread Objects Each thread is associated with an instance of the class Thread. There are two basic s ...

  9. 【PHP绘图技术&&验证码绘制】

    PHP绘图是比较简单的事情,基本绘图如直线.圆.矩形.弧线.填充矩形.填充扇形.非中文字的打印.中文文字的打印在在下面的代码中会纤细讲解. 需要支持中文的字体,可以到windows自带的字体库中找,并 ...

  10. 【PHP XML与dtd概述【完整版】】

    一.XML文件简介 关于XML的大多数人都知道一些,HTML->xhtml->xml,这个顺序本来应当是HTML发展的顺序. XML可以当做配置文件使用,还可以充当小型的数据库. vers ...