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. JPush集成

    JPush SDK 收到推送,通过广播的方式,转发给开发者App,这样开发者就可以灵活地进行处理. 这个动作不是必须的.用户有需要才定义 Receiver 类来处理 SDK过来的广播. 如果不做这个动 ...

  2. NYOJ题目198数数

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAK1CAIAAABEvL+NAAAgAElEQVR4nO3drXLkurvv8X0T4bmQYF

  3. velocity思维导图笔记

  4. SVM 最大间隔目标优化函数(NG课件2)

        目标是优化几何边距, 通过函数边距来表示需要限制||w|| = 1     还是优化几何边距,St去掉||w||=1限制转为普通函数边距     更进一步的,可以固定函数边距为1,调节||w| ...

  5. SQL索引及视图常用语法

    ALTER TABLE department ADD INDEX dept_name_idx (name); SHOW INDEX FROM department \G ALTER TABLE dep ...

  6. MyEclipse 关闭鼠标悬停提示

    preference --> MyEclipse -->Files and Editors--> Common Editor Preference --> Hovers 把里面 ...

  7. golang 索引

    入门的基础路线 a Tour of GoEffective GoGo By Example 以上的三部分通读算是入门. 4个重要的组成部分 1. 基础知识2. 并发特性3. 异常处理4. 常用开源项目 ...

  8. jq获取鼠标位置

    jq获取鼠标位置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  9. Parallel.js初探续集

    @author mrbean 例子均来源于github parallel.js 昨天写的第一篇今天一看居然有50+的阅读量了,感觉很激动啊,但是也有点害怕毕竟这只是自己笔记性质的一点东西,所以赶紧拿起 ...

  10. Servlet中的GET和POST之间的区别

    自己的感悟: get和post这是http协议的两种方法,另外还有head, delete等 这两种方法有本质的区别,get只有一个流,参数附加在url后,大小个数有严格限制且只能是字符串.post的 ...