题目链接: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. VB 调用动态链接库

    作为一种简单易用的Windows开发环境,Visual Basic从一推出就受到了广大编程人员的欢迎.它使 程序员不必再直接面对纷繁复杂的Windows消息,而可以将精力主要集中在程序功能的实现上,大 ...

  2. jdk升级到9,eclipse打不开

    jdk从1.8到1.9之后删除了不少之前Deprecated的类. eclipse 版本oxygen和neon对应jdk1.8 eclipse 版本luna和mars对应jdk1.7,1.6 在打开e ...

  3. python 安装mysqldb组件

    只能源码安装 源码下载: http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/ http://sourcefor ...

  4. js脚本代码调试小技巧

    以前写js代码调试代码查看数据是否正确的时候不知道F12(开发者工具),都是alert(xxx)或者console.log(xxx), 现在知道还可以用document.write或者try...ca ...

  5. 第三方苹果开发库之ASIHTTPRequest

    转载于:http://www.dreamingwish.com/dream-2011/apples-third-party-development-libraries-asihttprequest.h ...

  6. conductor APIs

    任务和工作流元数据 端点 描述 输入 GET /metadata/taskdefs 获取所有任务定义 N / A GET /metadata/taskdefs/{taskType} 检索任务定义 任务 ...

  7. jquery读取本地文件,Windows上报错。XMLHttpRequest cannot load xxx. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.k.cors.a.c

    问题: 测试报告,使用本地的json.txt文件,结果文件读取失败,报错如下: XMLHttpRequest cannot load xxx. Cross origin requests are on ...

  8. url获取参数

    参考http://www.runoob.com/w3cnote/js-get-url-param.html function getQueryVariable(variable) { var quer ...

  9. SpringCloud 简单理解

    0.SpringCloud,微服务架构.包括 服务发现(Eureka),断路器(Hystrix),服务网关(Zuul),客户端负载均衡(Ribbon).服务跟踪(Sleuth).消息总线(Bus).消 ...

  10. oracle的dmp数据文件的导出和导入以及创建用户

    关于dmp文件我们用的还是比较多的,dmp文件它是作为oracle导入和导出表使用的文件格式,今天就将dmp文件导出和导入进行学习. dmp文件导出 dmp文件导出用的比较多的一般是三种,他们分别是: ...