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. request.getParameter 乱码问题

    个简单的问题,我想追究一下深层次的原因: 前台的编码格式HTML里面的是utf-8的;; 但是后台使用request.getParameter("groupName");乱码; 我 ...

  2. UIColor+Hex

    #import <UIKit/UIKit.h> @interface UIColor (Hex) + (UIColor *)colorWithHex:(long)hexColor;+ (U ...

  3. 384. Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  4. 2 配置Ionic开发环境以及创建新的项目

    1.开发环境需要的软件有: node.js http://nodejs.org  可以到官方网站下载对应平台的安装包安装即可,如果已经安装,需要把它升级到最新的稳定版本   在终端可以输入$node ...

  5. Linux常用命令学习1---(安装、文件系统、目录操作命令cd ls mv cp rm mkdir、链接命令ln……)

    1.理解Linux的文件系统:分区和挂载点    挂载点和路径名无关 /根目录下的/boot完全可以时独立于 /的独立的挂载点,只要你设置就可以    linux安装时候,必须要有这两个分区 / 和 ...

  6. 使用html5 canvas绘制圆形或弧线

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  7. Vmware 中安装Unix

    准备 1. ubuntu 14.10 下载地址: 官网下载链接 http://www.ubuntu.com/download/desktop 官方版本库 http://releases.ubuntu. ...

  8. Java Socket编程示例

    一.Socket简介: 1.什么是Socket 网络上的两个程序通过一个双向的通讯连接实现数据的交换,这个双向链路的一端称为一个Socket.Socket通常用来实现客户方和服务方的连接.Socket ...

  9. WPF ItemsControl ListBox ListView比较

    在进行列表信息展示时,WPF中提供多种列表可供选择.这篇博客将对WPF ItemsControl, ListBox, ListView进行比较. 相同点: 1. 这三个控件都是列表型控件,可以进行列表 ...

  10. javascript中的true和false

    今天遇到一个问题,执行下面的代码返回true还是false?请说明理由 console.log([] == ![]) 在浏览器中运行了一下,发现结果是true.为什么会这样呢?于是查找了相关的资料. ...