hdu-1133
题目链接: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的更多相关文章
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...
- Buy the Ticket HDU 1133
传送门 [http://acm.hdu.edu.cn/showproblem.php?pid=1133] 题目描述和分析 代码 #include<iostream> #include< ...
- hdu 1133(卡特兰数变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元, ...
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- 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(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Buy the Ticket HDU 1133 卡特兰数应用+Java大数
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 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 ...
随机推荐
- ERROR 1222 (21000): The used SELECT statements have a different number of columns :
转自:https://blog.csdn.net/linshichen/article/details/52484224
- 机器学习入门-K-means算法
无监督问题,我们手里没有标签 聚类:相似的东西聚在一起 难点:如何进行调参 K-means算法 需要制定k值,用来获得到底有几个簇,即几种类型 质心:均值,即向量各维取平均值 距离的度量: 欧式距离和 ...
- Spring boot @ConfigurationProperties 和@Value
@ConfigurationProperties @Value 功能 批量注入配置文件中的属性 一个个指定 松散绑定(松散语法) 支持 不支持 SpEL 不支持 支持 JSR303数据校验 支持 ...
- AS3 注意点
当主类new 一个主影片来放内容的时候.在gc此swf时,一定要检查此主影片是否存在,如 private function initStart() { //trace("RightMenu类 ...
- 编写jQuery插件(三)——三个插件例子
封装jQuery对象方法的插件 表格隔行变色插件 CSS部分: .even{ background:#CCC; } .odd{ background:#666; } .selected{ backgr ...
- dmidecode详解
1.DMI简介 DMI (Desktop Management Interface, DMI)就是帮助收集电脑系统信息的管理系统,DMI信息的收集必须在严格遵照SMBIOS规范的前提下进行. SMBI ...
- Shiro权限总结
参考学习地址 shiro 瞅完就会用(ssm+shiro) Spring Shiro配置实现用户认证和授权 anon:它对应的过滤器里面是空的,什么都没做,另外.do和.jsp后面的*表示参 ...
- UGUI RectTransform
RectTransform解析 当 Anchor 在同一点时,显示的是物体的座标与大小Pos X.Pos Y.Width.Height ,当 Anchor 不在同一点时(此时会形成矩形),显示的会是 ...
- Unity C# 调用 C++ DLL 并在 DLL 中调用 C# 的回调函数
Unity C# 调用 C++ DLL 并在 DLL 中调用 C# 的回调函数~~~ 呵呵... 看着有点晕.. 再解释一下就是 在Unity中 使用 C# 调用 C++ 写的 DLL, 但是在 ...
- 梯度下降法】三:学习率衰减因子(decay)的原理与Python
http://www.41443.com/HTML/Python/20161027/512492.html