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 ...
随机推荐
- Redis五大数据结构
1.Redis介绍 Redis是REmote DIctionary Server的缩写,作者定位于一个内存KV存储数据库(In-memory key-value Store),让Redis自豪的并不是 ...
- Android触摸事件
简单介绍: 做了一个语音发送UI的小demo. 按下显示语音窗体,依据音量调节UI音量显示,上划至窗体显示取消发送. 原理: 1:获取什么事件来运行操作: 给Button加入setOnTouchLis ...
- 微博与Redis系统技术文章记录
Redis 持久化,有两种: rdb 和 aof, rdb是记录一段时间内的操作,一盘的配置是一段时间内操作超过多少次就持久化. aof可以实现每次操作都持久化. 这里我们使用aof. 配置方式,打开 ...
- 最小均方算法(LMS Algorithm)理论及DSP实现
LMS算法可认为是机器学习里面最基本也比较有用的算法,神经网络中对参数的学习使用的就是LMS的思想,在通信信号处理领域LMS也非常常见,比如自适应滤波器. 本文主要对LMS(Least Mean Sq ...
- [Python爬虫]煎蛋网OOXX妹子图爬虫(1)——解密图片地址
之前在鱼C论坛的时候,看到很多人都在用Python写爬虫爬煎蛋网的妹子图,当时我也写过,爬了很多的妹子图片.后来煎蛋网把妹子图的网页改进了,对图片的地址进行了加密,所以论坛里面的人经常有人问怎么请求的 ...
- Android导航抽屉-Navigation Drawer
Google今年七月份的时候更新了他们的Google+应用,采用了新的导航方式并抛弃了navigationdrawer.一时之间,又引发了一系列关于NavigationDrawer利弊的讨论,不过对于 ...
- Maximum Depth of Binary Tree leetcode java
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- ToolBarTray
<ToolBarTray DockPanel.Dock="Top"> <ToolBar ToolBarTray.IsLocked="True" ...
- [Algorithm] Largest sum of non-adjacent numbers
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Num ...
- Faiss学习:一
在多个GPU上运行Faiss以及性能测试 一.Faiss的基本使用 1.1在CPU上运行 Faiss的所有算法都是围绕index展开的.不管运行搜索还是聚类,首先都要建立一个index. import ...