HDUOJ---1133(卡特兰数扩展)Buy the Ticket
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3614 Accepted Submission(s): 1522
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.
推導過程如下:
#include<iostream>
#include<cstring>
#define maxn 500
using namespace std;
int arr[maxn+];
int main()
{
int m,n,time=,i,c,j,s,k; //m stand for person has 50 yuan, n stand for 100 yuan
while(cin>>m>>n,m+n)
{
memset(arr,,sizeof arr);
cout<<"Test #"<<time++<<":"<<endl;
if(m<n)
{
cout<<<<endl;
continue;
}
arr[]=;
for(i=,c=;i<=m+n;i++) //(m+n)!
{
for(j=;j<=maxn;j++)
{
s=arr[j]*i+c;
arr[j]=s%;
c=(s-arr[j])/;
}
}
for(c=j=;j<=maxn;j++) //(m+n)!*(m+1-n)
{
s=arr[j]*(m+-n)+c;
arr[j]=s%;
c=(s-arr[j])/;
}
for(k=maxn;arr[k]==;k--);
for(c=,j=k;j>=;j--) //(m+n)!*(m+1-n)/(m+1)
{
s=(arr[j]+*c);
c=s%(m+);
arr[j]=(s-c)/(m+);
}
for(k=maxn;arr[k]==;k--);
for(j=k;j>=;j--)
cout<<arr[j];
cout<<endl;
}
return ;
}
最新文章
- underscore.js库的浅析
- JDBC小工具--TxQueryRunner及其单元测试
- 网狐6603手机棋牌游戏源码.rar
- UI中的七种手势
- C#中的多线程-入门
- POJ 1703:Find them, Catch them(并用正确的设置检查)
- 3. [mmc subsystem] mmc core(第三章)——bus模块说明
- jieba库初级应用
- Ice_cream&#39;s world I(并查集成环)
- 第四百节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装python3.5.1
- 谈一谈Vector类
- mongodb的用法
- mysql-connector-java-5.1.22下载
- ZOJ2405 Specialized Four-Digit Numbers 2017-04-18 20:43 44人阅读 评论(0) 收藏
- SpringBoot源码分析之SpringBoot的启动过程
- Hadoop-2.7.2分布式安装手册
- 基于JavaSE阶段下的集合类汇总
- 同步网络时间到linux服务器(先修改时区再进行同步网络时间)
- std::string与output-operator";<;<;";的兼容问题
- Tkinter Dimensions
热门文章
- 解决hiveserver2报错:java.io.IOException: Job status not available - Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
- QT学习:c++解析html相关
- Rabbit MQ UI 重置 用户名 密码
- 第四章 第一个rabbitmq程序
- 架构师书单 2nd Edition
- Linq-语句之存储过程
- 在CentOS/RHEL上设置SSH免密码登录
- idea启动崩溃问题
- js 切换隐藏
- angular cli中的--flat参数