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.util.*; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cas = 1; while(tru…
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…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元钱的人可以不用找钱顺利买票,而拿着100元整钱的人只有在前面有50元的情况下才能买票,因为只有这样,才能找零50元.所有的人能否买票和排队的方式有一定关系,问使得所有的人能够顺利买票的排队方式有多少种? 上述问题可以抽象为下面的数学模型,数学模型及求解过程如下图: 本题中每个人是不一样的,所以本题的…
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…
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…
题目链接: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): 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…
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1个0,m+1个1. 总的数目=C(m+n,n),非法的=C(m+n,m+1) 符合数目=(C(m+n,n)-C(m+n,m+1))*m!*n!; 化简得:(m+n)!*(m+1-n)/(m+1). Java代码: import java.io.*; import java.math.*; import jav…
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #include <bits/stdc++.h> using namespace std; ; vector<string> vect; void _mult(string num1, string num2, string &result ) { reverse(num1.begin()…
Brackets Problem Description We give the following inductive definition of a “regular brackets” sequence:● the empty sequence is a regular brackets sequence,● if s is a regular brackets sequence, then (s) are regular brackets sequences, and● if a and…
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…
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…
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…
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…
题目链接:hdu 4828 Grids 题目大意:略. 解题思路:将上一行看成是入栈,下一行看成是出栈,那么执着的方案就是卡特兰数,用递推的方式求解. #include <cstdio> #include <cstring> typedef long long ll; const int N = 1000005; const ll MOD = 1e9+7; ll dp[N]; ll extendGcd(ll a, ll b, ll& x, ll& y) { if (…
Tree Maker Problem Description Tree Lover loves trees crazily. One day he invents an interesting game which is named Tree Maker. In this game, all trees are binary trees. Initially, there is a tree with only one vertex and a cursor on it. Tree Lover…
HDU 4828 Grids 思路:能够转化为卡特兰数,先把前n个人标为0.后n个人标为1.然后去全排列,全排列的数列.假设每一个1的前面相应的0大于等于1,那么就是满足的序列,假设把0看成入栈,1看成出栈.那么就等价于n个元素入栈出栈,求符合条件的出栈序列,这个就是卡特兰数了. 然后去递推一下解,过程中须要求逆元去计算 代码: #include <stdio.h> #include <string.h> const int N = 1000005; const long long…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6084 [题目大意] 对于一个串S,当它同时满足如下条件时,它就是一个01偏串: 1.只由0和1两种符组成: 2.在S的每一个前缀中,0的个数不超过1的个数: 3.S中0的个数和1的个数相等. 现在给定01偏串S,请计算一下S在所有长度为n的01偏串中作为子串出现的次数的总和. 由于结果比较大,结果对1e9+7取余后输出. [题解] 我们发现01偏串实际上等价于合法括号序列, 在合法括号序列中取出…
How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3382    Accepted Submission(s): 1960 Problem Description A binary search tree is a binary tree with root k such that any node v re…
HDU 4828 Grids 思路:能够转化为卡特兰数,先把前n个人标为0,后n个人标为1.然后去全排列,全排列的数列,假设每一个1的前面相应的0大于等于1,那么就是满足的序列.假设把0看成入栈,1看成出栈.那么就等价于n个元素入栈出栈,求符合条件的出栈序列,这个就是卡特兰数了.然后去递推一下解,过程中须要求逆元去计算 代码: #include <stdio.h> #include <string.h> const int N = 1000005; const long long…
题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4668    Accepted Submission(s): 2729 Problem Description Thi…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题意: 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如果机器人的当前位置在原点右侧,它同样可以向左移动单位距离.一系列的移动(左移,右移,原地不动)定义为一个路径.问有多少种不同的路径,使得n秒后机器人仍然位于坐标原点?答案可能很大,只需输出答案对1,000,000,007取模. 分析: 最终回到原点说明向左和向右走的步数相同,假设一共走了i步,那么左…
先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和出栈的次数都是n次,问最后栈空的合法序列的个数.其他例子见上面这个博客. 那么关于这个题目,我们先选出i次右移的(相当于进栈)次数,i次左移的(相当于出栈)次数,那么当前对答案做出的贡献就是C(n,2*i)*cat[i],枚举所有的i计算出答案即可. 代码如下: #include <stdio.h>…
Train Problem II Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing…
Robot Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There is a robot on the origin point of an axis.Every second, the robot can move right one unit length or do nothing.If the robot is on the…
Grids Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Problem Description 度度熊最近很喜欢玩游戏.这一天他在纸上画了一个2行N列的长方形格子.他想把1到2N这些数依次放进去,但是为了使格子看起来优美,他想找到使每行每列都递增的方案.不过画了很久,他发现方案数实在是太多了.度度熊想知道,有多少种放数字的方法能满足上面的条件?   Input 第一行为数…
Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasi…