hdu 1133 Buy the Ticket
首先,记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 java.math.BigInteger;
import java.lang.String.*;
import java.util.*;
public class Main
{
public static BigInteger [] p;
public static void main(String arg[])
{
int i;
p = new BigInteger[201];
p[0]=BigInteger.valueOf(1);
for(i=1;i<=200;i++)
p[i]=p[i-1].multiply(BigInteger.valueOf(i));
Scanner cin = new Scanner(System.in);
int k=1;
while(true)
{
int m = cin.nextInt();
int n = cin.nextInt();
if(m==0&&n==0) break; System.out.println("Test #"+k+++":");
if(m<n)
System.out.println("0");
else
System.out.println(p[m+n].multiply(BigInteger.valueOf(m+1-n)).divide(BigInteger.valueOf(m+1)).toString());
}
}
}
hdu 1133 Buy the Ticket的更多相关文章
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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 (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 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 ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- HDUOJ---1133(卡特兰数扩展)Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Buy the Ticket{HDU1133}
Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- daxuez.com
大学z,一个还没想好的名字和项目 初期定位:服务于武汉各大高校的大学学生群体 服务项目:兼职.旅游.培训.租车.班服订做.票务
- Vue.js 2.0版
Vue.js 2.0版升级,更改了好多方法或指令 new Vue({ el:'#demo', data:{ msg:"vue2.0" } }) v-model lazy numbe ...
- html5 app开发重大消息-腾讯在技术端推进Html5生态发展
中新网5月3日电 日前,腾讯正式发布腾讯浏览服务(Tencent Browser Service,以下简称TBS),宣布为合作伙伴提供整合腾讯底层技术.内容框架.广告体系以及大数据等多方面能力的升级浏 ...
- 无法安装程序包“MIcrosoft.Owin.Security 2.0.2”。您正在尝试将此程序包安装到某个将“.NETFramework,Version=v4.0”作为目标的项目中。
在VS2010 MVC4项目中,安装NuGet程序包Microsoft.AspNet.SignalR时出现以下错误: 原因是安装的版本是Microsoft.AspNet.SignalR 2.0.2,要 ...
- php威盾解密的例子分享
例子,批量解密 代码如下 复制代码 <?php/************************************威盾PHP加密专家解密算法 By:zhrt*http://www.111 ...
- 利用Unicode属性移除文本中的标点符号
原文:http://bbs.csdn.net/topics/270033191 摘抄: str = str.replaceAll("[\\pP‘’“”]", "&qu ...
- Global::pickSpecificTable_DNT
/*************************************************** Created Date: 13 Jul 2013 Created By: Jimmy Xie ...
- js各类共用方法
function GetParameterValueByName(parametername) { var reg = new RegExp("(^|&)" + param ...
- Spark菜鸟学习营Day2 分布式系统需求分析
Spark菜鸟学习营Day2 分布式系统需求分析 本分析主要针对从原有代码向Spark的迁移.要注意的是Spark和传统开发有着截然不同的思考思路,所以我们需要首先对原有代码进行需求分析,形成改造思路 ...
- allegro 16.6 空心焊盘的制作
手机键盘的按键就是空心焊盘,新建一个外径为0.6mm 内径为0.4mm 的空心焊盘 空心焊盘的制作如下: 一.新建一个空心的shape 1 shape -> Cirrular 在坐标处输入 x ...