题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133

思路:有m个人拿50元的纸币,n个人拿100元的纸币门票价格是50元,要求每个售票员遇到100元时都能找回顾客50元。

(1)如果m<n就不行,ans=0;

(2)m>=n,总共有C(m+n,n)种可能,只要求出不符合要求的即可。

假如有一个m=3,n=2的序列01100,它不合法,将第二个1后的0变为1,1变为0,得到01111,显然它也不合法。

由此可以看出每一个(m,n)序列都能由(m-1,n+1)序列推过来,所以不合法的序列数总共有C(m+n,m+1)个

,总共合法的序列有C(m+n,n)- C(m+n,m+1)=  (m+n)!*(m-n+1)/(m+1)个。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int base = ;
const int maxn = ;
int f[maxn*][maxn*],n,m,ans[maxn+];
void mul(int a[],int x)
{
int i,tmp=;
for(i=maxn-;i>=;i--)
{
tmp+=a[i]*x;
a[i]=tmp%base;
tmp/=base;
}
}
void chu(int a[],int x)
{
int i,tmp=;
for(i=;i<=maxn;i++)
{
tmp=tmp*base+a[i];
a[i]=tmp/x;
tmp%=x;
}
}
void Init()
{
f[][maxn-]=f[][maxn-]=;
for(int i=;i<=;i++)
{
memcpy(f[i],f[i-],maxn*sizeof(int));
mul(f[i],i);
}
}
int main(void)
{
int i,j,pt=;
Init();
while(~scanf("%d%d",&m,&n)&&(n+m))
{
printf("Test #%d:\n",pt++);
if(n>m)
{
printf("0\n");
continue;
}
memcpy(ans,f[n+m],maxn*sizeof(int));
mul(ans,m-n+);
chu(ans,m+);
i=;
while(ans[i]==) i++;
printf("%d",ans[i++]);
while(i<maxn) printf("%04d",ans[i++]);
printf("\n");
}
return ;
}

hdu-1133的更多相关文章

  1. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  2. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  3. Buy the Ticket HDU 1133

    传送门 [http://acm.hdu.edu.cn/showproblem.php?pid=1133] 题目描述和分析 代码 #include<iostream> #include< ...

  4. hdu 1133(卡特兰数变形)

      题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133   题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元, ...

  5. hdu 1133 Buy the Ticket

    首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...

  6. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  7. hdu 1133 Buy the Ticket(Catalan)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  8. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  9. hdu 1133 Buy the Ticket (大数+递推)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  10. HDU——1133 Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. PHP图像 因其本身有错无法显示

    昨天终于将客户的一个网站迁移至虚拟主机上,满怀希望的敲入网址.唰的一声,网站很轻松的被打开了. 心里那个高兴啊~~~ 咦,怎么产品图片都没有显示出来.一块块都是空白.敲入img src对应的地址,看看 ...

  2. 机器学习入门-数据下采样 np.random_choice

    1. np.random_choice(array, len)  进行随机的数据选择,array表示抽取的对象,len表示抽取样本的个数 数据的下采样是对多的数据进行np.random.choice ...

  3. 一步步实现 easyui datagrid表格宽度自适应,效果非常好

    一步步实现 easyui datagrid表格宽度自适应,效果非常好: 一.设置公共方法,使得datagrid的属性  fitColumns:true $(function(){ //初始加载,表格宽 ...

  4. Word 2003-在一个方框里打勾或打叉

    最近有个同事问我,如何在Word中输出一个方框中打勾的符号?查了一下帮助,其实很简单,特记录如下,供碰到的朋友参考: 一.在方框中打勾的方法: 先输入一个大写字母R,然后将R选中,将字体改为“Wind ...

  5. oracle 查看被锁的表和解锁

    相关视图 SELECT * FROM v$lock;SELECT * FROM v$sqlarea;SELECT * FROM v$session;SELECT * FROM v$process ;S ...

  6. 安装Anaconda以及jupyter的使用

    1)下载https://www.anaconda.com/download/ 2)安装 3)终端查看(Anaconda Prompt) 4)升级所有的包 初次安装下的软件包版本一般都比较老旧,因此提前 ...

  7. python webdriver启动IE浏览器

    from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapa ...

  8. Cannot resolve class or package 'dbcp' Cannot resolve class 'BasicDataSource'

    在applicationContext.xml中配置数据源时,报错如下: Cannot resolve class or package 'dbcp' Cannot resolve class 'Ba ...

  9. Spring编程式事务管理

    --------------------siwuxie095                                 Spring 编程式事务管理         以转账为例         ...

  10. Spring配置连接池

    ---------------------siwuxie095                                 Spring 配置连接池         1.Spring 配置内置连接 ...