1856: [Scoi2010]字符串(Catalan数)
1856: [Scoi2010]字符串
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 2117 Solved: 1211
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
HINT
【数据范围】
对于30%的数据,保证1<=m<=n<=1000
对于100%的数据,保证1<=m<=n<=1000000
Source
/*
LuoguAC,bzoj总是CE我也很绝望啊
Catelan数。
等价于画一个坐标系从(0,0)到n-m且不越过y=-1(即1的个数>=0)这条线的方案数。
把y=n-m关于y=-1对称。则每一个不合法的解都对应一条从(0,0)到y=m-n-2的路径(画图可知)
答案就是总方案数减去不合法的路径条数。
考虑放x个1,则有 x-(n+m-x)=m-n-2 (到达y=m-n-2) 解得x=m-1。
不合法的路径条数就是C(m+n,m-1)
*/
#include<bits/stdc++.h> #define N 2000002
#define M 20100403
#define ll long long using namespace std;
ll n,m,ans;
ll inv[N]={,},fac[N]={,},f[N]={,}; int ll C(ll a,ll b)
{
return ((fac[a]*inv[b])%M*inv[a-b]%M)%M;
} inline void init()
{
fac[]=;
for(int i=;i<=n+m+;i++)
{
fac[i]=(fac[i-]%M*i)%M;
f[i]=((M-M/i)*f[M%i])%M;
inv[i]=(inv[i-]*f[i])%M;
}
} int main()
{
cin>>n>>m;
init();
ans=(C(n+m,n)%M-C(m+n,m-)%M+M)%M;
cout<<ans<<endl;
return ;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 20100403
#define ll long long
using namespace std; ll n,m;
ll mul[],inv[]; ll c(ll x,ll y)
{
return (((mul[x]*inv[x-y])%mod)*inv[y])%mod;
} int main()
{
scanf("%lld%lld",&n,&m);
mul[]=mul[]=inv[]=inv[]=;
ll tot=m+n;
for(ll i=;i<=tot;i++)mul[i]=mul[i-]*i%mod;
for(ll i=;i<=tot;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(ll i=;i<=tot;i++)inv[i]=inv[i]*inv[i-]%mod;
ll ans=((c(tot,n)-c(tot,n+))%mod+mod)%mod;
printf("%lld\n",ans);
return ;
}
1856: [Scoi2010]字符串(Catalan数)的更多相关文章
- BZOJ 1856: [Scoi2010]字符串 [Catalan数]
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1418 Solved: 790[Submit][Status][ ...
- Bzoj 1856: [Scoi2010]字符串 卡特兰数,乘法逆元,组合数,数论
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1194 Solved: 651[Submit][Status][ ...
- bzoj 1856: [Scoi2010]字符串 卡特兰数
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1458 Solved: 814[Submit][Status][ ...
- 【bzoj1856】[Scoi2010]字符串 Catalan数
题目描述 lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgww想要知道满足 ...
- BZOJ 1856: [Scoi2010]字符串( 组合数 )
求(0,0)->(n,m)且在直线y=x下方(可以在y=x上)的方案数...同 http://www.cnblogs.com/JSZX11556/p/4908648.html --------- ...
- 1856: [Scoi2010]字符串
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 847 Solved: 434[Submit][Status] D ...
- 【BZOJ】1856: [Scoi2010]字符串
http://www.lydsy.com/JudgeOnline/problem.php?id=1856 题意:把n个1和m个0组成字符串,要求在组成的字符串中,任意的前k个字符1的个数不能少于0的个 ...
- 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 ...
随机推荐
- 写2个线程,其中一个线程打印1~52,另一个线程打印A~z,打印顺序应该是12A34B45C……5152Z
我写的 class LN { private int flag = 0; public static char ch = 'A'; public static int n = 1; public sy ...
- Java中常见的注解
Java中常见的注解 1.JDK自带的注解@Override @Deprecated @Suppvisewarnings 常见第三方注解 Spring:@Autowired @Service ...
- Linux MySQL主从复制(Replication)配置
MySQL是开源的关系型数据库系统.复制(Replication)是从一台MySQL数据库服务器(主服务器master)复制数据到另一个服务器(从服务器slave)的一个进程. 配置主服务器(mast ...
- Arcgis Engine(ae)接口详解(2):featureClass查询
//属性查询~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //IQueryFilter代表查询条件,QueryFilterClass代表只限于属性查询(就是没有空间查询) ...
- 如何删除ini文件中的内容
1.删除子项值:::WritePrivateProfileString(分区名称, 子项名称, "", ini文件路径); 2.删除子项(名称和值):::WritePrivateP ...
- 2016/06/13 phpexcel 未完待续
①准备工作: 1,php版本不能太低 2,去官网下载PHPExcel插件 http://phpexcel.codeplex.com/ 3,解压后提取classes文件夹到工作目录,并重命名为PH ...
- Get Luffy Out (poj 2723 二分+2-SAT)
Language: Default Get Luffy Out Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7969 ...
- C++设计模式之State模式
这里有两个例子: 1.https://www.cnblogs.com/wanggary/archive/2011/04/21/2024117.html 2.https://www.cnblogs.co ...
- (linux)schedule_delayed_work()
原文地址:schedule_delayed_work()用法作者:Valley 第一篇 工作队列 在Linux内核中,对下半部(或者说推后执行的工作)的处理方式有好几种,包括BH( ...
- flywaydb and sql server
https://flywaydb.org/documentation/database/sqlserver How Flyway works https://flywaydb.org/getstart ...