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(true){
int m = sc.nextInt();
int n = sc.nextInt();
if(m == 0 && n == 0)
break;
System.out.println("Test #"+cas+":");
cas++;
if(m < n){
System.out.println(0);
continue;
}
BigInteger ans1 = BigInteger.valueOf(1);
int x = n+m;
for(int i = 1; i <= m; i++){
ans1 = ans1.multiply(BigInteger.valueOf(x));
x--;
}
for(int i = 1; i <= n; i++){
ans1 = ans1.multiply(BigInteger.valueOf(i));
}
BigInteger ans2 = BigInteger.valueOf(1);
x = n+m;
for(int i = 1; i <= m+1; i++){
ans2 = ans2.multiply(BigInteger.valueOf(x));
x--;
ans2 = ans2.divide(BigInteger.valueOf(i));
}
for(int i = 1; i <= n; i++){
ans2 = ans2.multiply(BigInteger.valueOf(i));
}
for(int i = 1; i <= m; i++){
ans2 = ans2.multiply(BigInteger.valueOf(i));
} System.out.println(ans1.subtract(ans2));
}
}
}
HDU 1133 Buy the Ticket 卡特兰数的更多相关文章
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 【hdoj_1133】Buy the Ticket(卡特兰数+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元 ...
- HDU 1133 Buy the Ticket (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU1133 Buy the Ticket —— 卡特兰数
题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdu 1133 Buy the Ticket (大数+递推)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU——1133 Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
随机推荐
- Java 遍历Map对象的4种方法
http://blog.csdn.net/tjcyjd/article/details/11111401
- Scala-基础-流程控制语句
import junit.framework.TestCase import scala.util.control.Breaks._ //流程控制语句 //关键字 if else match clas ...
- [ SPOJ PT07J ] Query on a tree III
\(\\\) Description 其实这题才是正版的 Qtree3...... 给定 \(n\) 个点,以 \(1\) 号节点为根的树,点有点权. \(m\) 次询问 以 \(x\) 为根的子树内 ...
- git Eclipse项目不显示当前分支
问题: 在Eclipse中,导入新的git项目,在项目上不再显示当前所处的分支,也不再显示修改了哪些文件 解决: 右键选中项目 --> Team --> Share Project ...
- 可滚动的ResultSet类型 实现分页
可滚动的ResultSet类型. 这个类型支持前后滚动取得纪录next().previous(),回到第一行first(),同时还支持要取的 ResultSet中的第几行 absolute(int n ...
- JS高级——Blob处理二进制文件
https://www.cnblogs.com/hhhyaaon/p/5928152.html
- 北大ACM(POJ1019-Number Sequence)
Question:http://poj.org/problem?id=1019 问题点:打表. Memory: 392K Time: 16MS Language: C++ Result: Accept ...
- Java 基础入门随笔(8) JavaSE版——静态static
面向对象(2) this:代表对象.代表哪个对象呢?当前对象. 当成员变量和局部变量重名,可以用关键字this来区分. this就是所在函数所属对象的引用.(简单说:哪个对象调用了this所在的函数, ...
- 使用脚本快速线程转储及列出高cpu线程
jstack `ps -ef | grep java | grep bocai.jar | awk '{print $2}'` > cpu_high.logtop -b -n1 -Hp `ps ...
- dutacm.club_1089_A Water Problem_(dp)
题意:要获得刚好后n个'k'的字符串,有两种操作,1.花费x秒,增加或删除1个'k'; 2.花费y秒,使个数翻倍.问最少需要多少时间获得这个字符串. 思路:i为偶数个'k',dp[i]=min(dp[ ...