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 ...
随机推荐
- jquery formValidator 表单验证插件, ajax无法传值到后台问题的解决
今天使用jquery formValidator-4.0.1 这个插件做表单验证, 前台验证已写好, 准备写ajax验证, 结果无法把值传到后台 .ajaxValidator({ url : & ...
- jsfl 巧用获取jsfl绝对路径,导入配置文件,注意配置文件无法改变舞台宽高
//获取jsfl下的AS3.xml配置文件的路径 var jsflURL_arr=fl.scriptURI.split("/"); jsflURL_arr.splice(jsflU ...
- ABAP-SMARTFORMS
- UGUI RectTransform
RectTransform解析 当 Anchor 在同一点时,显示的是物体的座标与大小Pos X.Pos Y.Width.Height ,当 Anchor 不在同一点时(此时会形成矩形),显示的会是 ...
- DataType 数据类型
基本类型:四类八种:数值 : 整数:byte,short,int,long.默认是 int 小数:float,double 默认是 double 布尔:boolean ...
- js ParseUrl
js ParseUrl function parseURL(url) { var a = document.createElement('a'); a.href = url; return { sou ...
- 解决selenium不支持firefox低版本的问题
解决selenium不支持firefox低版本的问题 在火狐浏览器升级后,突然发现webdriver运行脚本的时候不能调出火狐浏览器了,并报错WebDriverException:Message:'C ...
- SSH框架分模块开发
------------------siwuxie095 SSH 框架分模块开发 1.在 Spring 核心配置文件中配置多个内容,容易造成 配置混乱,不利于维护 「分模块开发主要针对 Spring ...
- css学习-css引入&css选择
一.引入css的方式,一共有4种,我们只需要掌握三种就可以了,@import的方法我们不做掌握 1.第一种引入的方法 <!--1.第一种引入css的方法--> <h1 style=& ...
- 清空表中数据 id从1开始
删除表的记录以后,如何使新记录的编号仍然从1开始有两种方法: 方法1: truncate table 你的表名 --这样不但将数据删除,而且可以重新置位identity属性的字段. 方法2: dele ...