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 ...
随机推荐
- callback调用测试
<html> <head> <script> var context="全局"; var testObj={ context:"初始& ...
- C#简单实现发送手机短信
偶然想起,像编写一个从电脑向手机发送短信的程序,从网上查找到有三种方式:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册;(2) ...
- php + apache + mysql环境搭建
别人写的很好,若是不改变php默认访问路径的话,能够成功搭建是没问题的 http://www.cnblogs.com/pharen/archive/2012/02/06/2340628.html
- vc列表控件的初始化
void CManageProcessDlg::InitList() { m_ListProcess.SetExtendedStyle(m_ListProcess.GetExtendedStyle( ...
- 【转】char*,const char*和string的相互转换
1. string转const char* string s = "abc"; const char* c_s = s.c_str(); 2. const char*转string ...
- linux c 实现大数相乘
#include <stdio.h> #include <string.h> #include <math.h> #include <stdbool.h& ...
- 栈帧%ebp,%esp详解
首先应该明白,栈是从高地址向低地址延伸的.每个函数的每次调用,都有它自己独立的一个栈帧,这个栈帧中维持着所需要的各种信息.寄存器ebp指向当前的栈帧的底部(高地址),寄存器esp指向当前的栈帧的顶部( ...
- PHP中::、->、self、$this操作符的区别
在访问PHP类中的成员变量或方法时,如果被引用的变量或者方法被声明成const(定义常量)或者static(声明静态),那么就必须使用操作符::,反之如果被引用的变量或者方法没有被声明成const或者 ...
- matlab实现雅可比、高斯塞德尔、后项误差计算
稀疏矩阵生成: function [a, b] = aparsesetup(n) e = ones(n, 1); n2 = n / 2; a = spdiags([-e 3*e -e], -1:1, ...
- skrollr 中文教程
skrollr 0.6.29 skrollr是一个单独的视差滚动的JavaScript库,移动端(Android,iOS,等)和pc都可以使用,压缩后大小仅仅不到12K 使用方法 首先你需要引入skr ...