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 ;
- }
HDUOJ---1133(卡特兰数扩展)Buy the Ticket的更多相关文章
- Buy the Ticket HDU 1133 卡特兰数应用+Java大数
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- CodeForces - 1204E Natasha, Sasha and the Prefix Sums (组合数学,卡特兰数扩展)
题意:求n个1,m个-1组成的所有序列中,最大前缀之和. 首先引出这样一个问题:使用n个左括号和m个右括号,组成的合法的括号匹配(每个右括号都有对应的左括号和它匹配)的数目是多少? 1.当n=m时,显 ...
- HDOJ 5184 Brackets 卡特兰数扩展
既求从点(0,0)仅仅能向上或者向右而且不穿越y=x到达点(a,b)有多少总走法... 有公式: C(a+b,min(a,b))-C(a+b,min(a,b)-1) /// 折纸法证明卡特兰数: h ...
- hdu 1133(卡特兰数变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元, ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 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 ...
- 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Buy the Ticket(卡特兰数+递推高精度)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
随机推荐
- 【视频分享】Liger UI实战集智建筑project管理系统配商业代码(打印报表、角色式权限管理)
QQ 2059055336 课程讲师:集思博智 课程分类:.net 适合人群:中级 课时数量:23课时 用到技术:Liger UI框架.AJAX.JSON数据格式的序列化与反序列化.角色的交叉权限管理 ...
- C语言运算符优先级及结合性
今天去翻了下C语言运算符的优先级和结合性,发现当初学习的时候就没认真记住,惭愧.发现一篇讲得不错的文章,编辑了下转来供以后翻阅. C语言运算符优先级表(由上至下,优先级依次递减) 运算符 结合性 () ...
- Cocos2dx 3.0 过渡篇(二十七)C++11多线程std::thread的简单使用(下)
本篇接上篇继续讲:上篇传送门:http://blog.csdn.net/star530/article/details/24186783 简单的东西我都说的几乎相同了,想挖点深的差点把自己给填进去. ...
- 如何重构"箭头型"代码
本文主要起因是,一次在微博上和朋友关于嵌套好几层的if-else语句的代码重构的讨论(微博原文),在微博上大家有各式各样的问题和想法.按道理来说这些都是编程的基本功,似乎不太值得写一篇文章,不过我觉得 ...
- Objective-C:保留计数器思想的详解(对象的保留和所有权的释放)
对象的保留和所有权的释放: int main(int agrs,char *argv[]) { @autoreleasepool{ Person *person = [[Person alloc]in ...
- OpenCV学习(31) 基于defects的简单手势
前几年在做毕业设计时候曾用opencv1.0中defects做过简单的手势识别,这几天看OpenCV2.46中的轮廓函数,发现和以前差别挺大,函数调用完全不一样,重新实现了简单手势的代码. 1.首先用 ...
- eclipse svn 配置
1.安装svn http://subversion.apache.org/ 到apache网站上下载svn 2.在eclipse中安装svn插件 在eclipse->help->eclip ...
- 我所遭遇过的游戏中间件--PhysX
我所遭遇过的游戏中间件--PhysX PhysX现在是Nvidia的物理中间件.其特点是简练且功能强大.当我最初拿到PHYSX的SDK时,就发现这个物理中间件比Havok要小很多,但该有的功能都有,甚 ...
- 值得收藏的十二条Jquery随身笔记
1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...
- Element table使用技巧详解
1.控制table某些行数不显示 下载附件的需求,有些行有附件,有些没有,所以需要过滤,重点是:Array.filter()使用 <el-card :body-style="{ pad ...