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 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next…
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…
题意:求n个1,m个-1组成的所有序列中,最大前缀之和. 首先引出这样一个问题:使用n个左括号和m个右括号,组成的合法的括号匹配(每个右括号都有对应的左括号和它匹配)的数目是多少? 1.当n=m时,显然答案为卡特兰数$C_{2n}^{n}-C_{2n}^{n+1}$ 2.当n<m时,无论如何都不合法,答案为0 3.当n>m时,答案为$C_{n+m}^{n}-C_{n+m}^{n+1}$,这是一个推论,证明过程有点抽象,方法是把不合法的方案数等价于从(0,-2)移动到(n+m,n-m)的方案数,…
既求从点(0,0)仅仅能向上或者向右而且不穿越y=x到达点(a,b)有多少总走法... 有公式: C(a+b,min(a,b))-C(a+b,min(a,b)-1)  /// 折纸法证明卡特兰数: http://blog.sina.com.cn/s/blog_6917f47301010cno.html Brackets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total…
  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133   题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元,每人编号各不相同.问有多少种排队方案? 题解: 当 m<n时,肯定方案数是0. 当m>=n时,将队伍看成一个栈,持有50的人用0表示,持有100的人用1表示. 对于n+m个数我们能有的总方案数有C(n+m,n)种. 不符合的方案数:(以下是百度百科的解释) 考虑一个含n个1.n个0的2n位二进制数…
Buy the Ticket 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 tic…
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…
设50元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java.util.*; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cas = 1; while(tru…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4726    Accepted Submission(s): 1993 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1886 Accepted Submission(s): 832   Problem Description The \\\\\\\"Harry Potter and the Goblet of Fire\\\\\\\" will be on show i…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元钱的人可以不用找钱顺利买票,而拿着100元整钱的人只有在前面有50元的情况下才能买票,因为只有这样,才能找零50元.所有的人能否买票和排队的方式有一定关系,问使得所有的人能够顺利买票的排队方式有多少种? 上述问题可以抽象为下面的数学模型,数学模型及求解过程如下图: 本题中每个人是不一样的,所以本题的…
题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7427    Accepted Submission(s): 3105 Problem Description The "Harry Potter and the Goblet…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8838    Accepted Submission(s): 3684 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next…
题目链接 分析:打表以后就能发现时卡特兰数, 但是有除法取余. f[i] = f[i-1]*(4*i - 2)/(i+1); 看了一下网上的题解,照着题解写了下面的代码,不过还是不明白,为什么用扩展gcd, 不是用逆元吗.. 网上还有别人的解释,没看懂,贴一下: (a / b) % m = ( a % (m*b)) / b 笔者注:鉴于ACM题目特别喜欢M=1000000007,为质数: 当gcd(b,m) = 1, 有性质: (a/b)%m = (a*b^-1)%m, 其中b^-1是b模m的逆…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5651    Accepted Submission(s): 2357 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
[SCOI2010]生成字符串 Description lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgww想要知道满足要求的字符串共有多少个,聪明的程序员们,你们能帮助他吗? 输入格式:输入数据是一行,包括2个数字n和m; 输出格式:输出数据是一行,包括1个数字,表示满足要求的字符串数目,这个数可能会很大,只需输出这个数除以20100403的余数; Solution 1…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4185    Accepted Submission(s): 1759 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7152    Accepted Submission(s): 2998 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume…
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5566    Accepted Submission(s): 2326 Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the nex…
How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3397    Accepted Submission(s): 1964 Problem Description A binary search tree is a binary tree with root k such that any node v re…
题意:给定2行n列的长方形,然后把1—2*n的数字填进方格内,保证每一行,每一列都是递增序列,求有几种放置方法,对1000000007取余: 思路:本来想用组合数找规律,但是找不出来,搜题解是卡特兰数,而且还有一个难点在于N的范围是1000000,卡特兰数早已数千位,虽然有取余: 解决方法就是用在求卡特兰数的时候快速取余+带模除法: 卡特兰数递归公式1:K(n)=K(n-1) * ((4*n-2)/(n+1)); 组合数公式2:K[n] = C[2*n][n] /(n+1); 看公式1,有个除法…
因为规定n层的阶梯只能用n块木板 那么就需要考虑,多出来的一块木板往哪里放 考虑往直角处放置新的木板 不管怎样,只有多的木板一直扩展到斜边表面,才会是合法的新状态,发现,这样之后,整个n层阶梯就被分成了i层和n-1-i层的阶梯,即 f(n)=∑i=0n−1f(i)×f(n−1−i) 就是卡特兰数!!!,需要高精..差评.. #include<cstdio> #include<cstring> #include<iostream> #include<algorith…
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tou…
一.卡特兰数(Catalan number) 1.定义 组合数学中一个常出现在各种计数问题中出现的数列(用c表示).以比利时的数学家欧仁·查理·卡特兰的名字来命名: 2.计算公式 (1)递推公式 c[n]=Σ(0≤k<n)c[k]c[n-k-1],边界条件为c[0]=1; 其递推解为c[n]=C(2n,n)/(n+1),即卡特兰数的通项公式,其中C表示数的组合: 根据组合公式我们可以化简得c[n]=2n(2n-1).....(n+2)/n!; (2)另类递推式 c[n]=c[n-1](4n-2)…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12035    Accepted Submission(s): 6422 Problem Description As we all know the…
链接:https://www.nowcoder.com/acm/contest/85/I题目描述 あなたの蛙が帰っています!  蛙蛙完成了一趟旅行,回家啦!但它还是没有去它心中非常想去的几个地方.总共有 N 个它 想去的目的地.蛙蛙下定了决心,它要做一个愿望清单,一定要让自己去那些想去的地方.蛙蛙 是这样做的:它会不定时地想起一个或多个目的地,然后按顺序写在愿望清单上.但是每次蛙蛙 出去旅行时,都会先去最近写在愿望清单上的地方,并且蛙蛙不会重复去一个目的地,但它会去 访问所有的目的地.蛙蛙有个最…
题目:bzoj3907:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 bzoj2822:https://www.lydsy.com/JudgeOnline/problem.php?id=2822 bzoj3907: 从网格图的角度很好想啊,就是像定义一样,一下子就出来了 ans = C(n+m,n) - C(n+m,m-1): 那么从01串的角度呢?这个是0和1的个数不同的问题呢... 看到这篇博客:https://blog.csdn…
[HNOI 2009] 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所有的奇数项满足a1<a3<…<a2n-1,所有的偶数项满足a2<a4<…<a2n: (3)任意相邻的两项a2i-1与a2i(1≤i≤n)满足奇数项小于偶数项,即:a2i-1<a2i. 现在的任务是:对于给定的n,请求出有多少个不同的长度为2n的有趣的数列.因为最后的答案可能很大,所以只要求输出答案 mod P的…
题目 题目描述 今天,接触信息学不久的小\(A\)刚刚学习了卡特兰数. 卡特兰数的一个经典定义是,将\(n\)个数依次入栈,合法的出栈序列个数. 小\(A\)觉得这样的情况太平凡了.于是,他给出了\(m\)组限制,每个限制形如\((f_i,g_i)\),表示\(f_i\)不能在\(g_i\)之后出栈. 他想求出:在满足了这\(m\)组限制的前提下,共有多少个合法的出栈序列.他不喜欢大数,你只需要求出答案在模\(998244353\)意义下的值即可. 输入格式 输入第一行为两个非负整数,\(n\)…