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 ...
随机推荐
- wikioi 1163 訪问艺术馆 树形dp
递归建树,由题知该树是一棵二叉树,且除根节点外其它点的度为0或2. dp[i][j]表示来到第i个走廊(还未走过这条走廊)还剩下j时间,能拿到最大的画的数量. dp[i][j]=max(dp[i][j ...
- 近看到的机器学习、NLP相关书单
书单再多,不去读,也是白搭~~ 水木上的machine learning书单:http://www.newsmth.net/bbscon.php?bid=5&id=34859&ftyp ...
- Spark GraphX图处理编程实例
所构建的图如下: Scala程序代码如下: import org.apache.spark._ import org.apache.spark.graphx._ // To make some of ...
- java中需要用equals来判断两个字符串值是否相等
在C++中,两个字符串比较的代码可以为: (string1==string2) 但在java中,这个代码即使在两个字符串完全相同的情况下也会返回false Java中必须使用string1.equal ...
- go语言基础之go猜数字游戏
1. 产生一个随机的4位数 示例1: package main import "fmt" import "math/rand" import "tim ...
- Android 跳转到系统应用管理
Intent i = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");String pkg = " ...
- input框设置onInput事件只能输入数字,能兼容火狐IE9
使用onInput()事件 onInput()是 HTML5 的标准事件,对于检测 textarea, input:text, input:password 和 input:search 这几个元素通 ...
- 数据库操作语句类型(DQL、DML、DDL、DCL)简介
SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL. 1. 数据查询语言DQL数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHER ...
- MongoDB学习笔记(六)--复制集+sharding分片 && 总结
复制集+sharding分片 背景 主机 IP 服务及端口 Server A ...
- URAL 1807
题目大意:给出一个正整数n(n为合数),求n的一个划分(a1,a2,...,ak,...)(k>=2).使得其在存在最大的最大公约数之下,存在最大的最小公倍数. KB 64bit IO ...