Bzoj 1856: [Scoi2010]字符串 卡特兰数,乘法逆元,组合数,数论
1856: [Scoi2010]字符串
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 1194 Solved: 651
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
HINT
【数据范围】
对于30%的数据,保证1<=m<=n<=1000
对于100%的数据,保证1<=m<=n<=1000000
Source
题解:
在任意的前k个字符中,1的个数不能少于0的个数 ???
好熟悉。。。卡特兰数。。。
当然你也可以在纸上推一下。
直接套公式:当n为1的个数,m为0的个数时,卡特兰数为C(n+m,n)-C(n+m,m-1)。
组合数C(n,r)直接用逆元计算即可。
#include<bits/stdc++.h>
using namespace std;
#define MOD 20100403
#define LL long long
LL ksm(LL bb,LL pp,LL kk)
{
LL s=;
while(pp>)
{
if(pp%!=)s=(s*bb)%kk;
pp/=;
bb=(bb*bb)%kk;
}
return s;
}
LL C(LL n,LL m)
{
LL s1=,s2=,nn=n,i;
if(m>n-m)m=n-m;
for(i=;i<=m;i++)
{
s1=(s1*nn)%MOD;nn--;
s2=(s2*i)%MOD;
}
return (s1*ksm(s2,MOD-,MOD))%MOD;
}
int main()
{
LL n,m;
scanf("%lld %lld",&n,&m);
printf("%lld",((C(n+m,n)-C(n+m,m-))%MOD+MOD)%MOD);
fclose(stdin);
fclose(stdout);
return ;
}
Bzoj 1856: [Scoi2010]字符串 卡特兰数,乘法逆元,组合数,数论的更多相关文章
- bzoj 1856: [Scoi2010]字符串 卡特兰数
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1458 Solved: 814[Submit][Status][ ...
- BZOJ 1856: [Scoi2010]字符串 [Catalan数]
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1418 Solved: 790[Submit][Status][ ...
- 1856: [Scoi2010]字符串(Catalan数)
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 2117 Solved: 1211[Submit][Status] ...
- BZOJ 1856: [Scoi2010]字符串( 组合数 )
求(0,0)->(n,m)且在直线y=x下方(可以在y=x上)的方案数...同 http://www.cnblogs.com/JSZX11556/p/4908648.html --------- ...
- HDU 4828 Grids(卡特兰数+乘法逆元)
首先我按着我的理解说一下它为什么是卡特兰数,首先卡特兰数有一个很典型的应用就是求1~N个自然数出栈情况的种类数.而这里正好就对应了这种情况.我们要满足题目中给的条件,数字应该是从小到大放置的,1肯定在 ...
- bzoj 1856: [Scoi2010]字符串
#include<cstdio> #include<iostream> #define Q 20100403 ; int main() { scanf("%lld%l ...
- BZOJ1856:[SCOI2010]字符串(卡特兰数,组合数学)
Description lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgw ...
- 1856: [Scoi2010]字符串
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 847 Solved: 434[Submit][Status] D ...
- Luogu 1641[SCOI2010]生成字符串 - 卡特兰数
Description 有$N$ 个 $1$ 和 $M$ 个 $0$ 组成的字符串, 满足前 $k$ 个字符中 $1$ 的个数不少于 $0$ 的个数. 求这样字符串的个数. $1<=M < ...
随机推荐
- 深入了解float
1.float的历史 初衷是为了图片的文字环绕,将img设置float 2.破坏性与包裹性 a.父元素没有设置高度,内部元素浮动后,服务元素的高度被破坏了,可以将其父元素设置overflow:h ...
- 响应式页面字体用什么单位:rem
html:62.5%//10pxbody:1.4rem;//14px... <!doctype html> <html> <head> <title>a ...
- ionic移动开发入门
学习资料:http://www.ionic.wang http://www.ionicframework.com/
- WPF 得一些问题汇总
1.CallMethodAction <TextBox Height="30" Name="txtUserName" Width="160&qu ...
- css常用伪类记录
1.超链接使用css伪类设置颜色 a:link {color: #000000} /* 未访问的链接 */a:visited {color: #d90a81} /* 已访问的链接 */a:hover ...
- Android中的pix,sp,dp相关概念
px( pixel) 像素,可以简单的理解为一个点或方块,用以颜色的显示(单位),一般指印刷品或屏幕设置设备的颜色显示定义. dip(device independent pixels)设备独立像素. ...
- OC - 正则表达式 - RegexKitLite
正则表达式使用步骤: 1. 创建正则表达式对象, 设置约束条件; NSString *pattern = @"\\d{1,3}"; NSRegularExpression *reg ...
- UIWebView1-b
随着H5的强大,hybrid app已经成为当前互联网的大方向,单纯的native app和web app在某些方面显得就很劣势.关于H5的发展史,这里有一篇文章推荐给大家,今天我们来学习最基础的基于 ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MB Submit: 665 Solved: 227[Sub ...
- Hdu 2971 Tower
Description Alan loves to construct the towers of building bricks. His towers consist of many cuboid ...