BZOJ1856:[SCOI2010]字符串(卡特兰数,组合数学)
Description
Input
Output
Sample Input
Sample Output
HINT
【数据范围】
对于30%的数据,保证1<=m<=n<=1000
对于100%的数据,保证1<=m<=n<=1000000
Solution
只要看懂这个博客方法二的证明,就可以发现这个题只不过是那个证明变了一点而已。
只需要做起点的对称点用总路径减去不合法路径即可。
最后答案是C(m+n,n)-C(m+n,n+1)
Code
#include<iostream>
#include<cstdio>
#define N (2000000+1000)
#define MOD (20100403)
using namespace std;
long long n,m,Fact[N],FactInv[N],Inv[N],ans; long long C(long long n,long long m)
{
if (m>n) return ;
return Fact[n]*FactInv[m]%MOD*FactInv[n-m]%MOD;
} int main()
{
scanf("%lld%lld",&n,&m);
Inv[]=Inv[]=Fact[]=Fact[]=;
for (int i=; i<=m+n; ++i)
{
Fact[i]=Fact[i-]*i%MOD;
Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
} FactInv[]=;
for (int i=; i<=m+n; ++i)
FactInv[i]=Inv[i]*FactInv[i-]%MOD;
printf("%lld",((C(m+n,n)-C(m+n,n+))%MOD+MOD)%MOD);
}
BZOJ1856:[SCOI2010]字符串(卡特兰数,组合数学)的更多相关文章
- 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][ ...
- Luogu 1641[SCOI2010]生成字符串 - 卡特兰数
Description 有$N$ 个 $1$ 和 $M$ 个 $0$ 组成的字符串, 满足前 $k$ 个字符中 $1$ 的个数不少于 $0$ 的个数. 求这样字符串的个数. $1<=M < ...
- 2018.09.25 bzoj1856: [Scoi2010]字符串(组合数学)
传送门 如果有n==m的条件就是卡特兰数. 但现在n不一定等于m. 我们可以考虑用求卡特兰数一样的方法来求答案. 我们知道有一种求卡特兰数的方法是转到二维平面求答案. 这道题就可以这样做. 我们将这个 ...
- BZOJ 1856: [Scoi2010]字符串 [Catalan数]
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1418 Solved: 790[Submit][Status][ ...
- uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)
option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...
- 1856: [Scoi2010]字符串(Catalan数)
1856: [Scoi2010]字符串 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 2117 Solved: 1211[Submit][Status] ...
- bzoj千题计划299:bzoj1856: [Scoi2010]字符串
http://www.lydsy.com/JudgeOnline/problem.php?id=1856 卡特兰数 从(1,1)走到(n,m),不能走y=x 上方的点,求方案数 从(1,1)走到(n, ...
- Train Problem II(卡特兰数 组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
随机推荐
- vue中使用对非表单元素使用contenteditable的问题
先说下问题,再上解决方案: span编辑时有多余空格和回车会影响样式(我用的是span便以此为例) 代码:(有换行符) 效果图: 代码:(无换行符) 效果图: 当在span标签的contentedit ...
- DB Intro - MongoDB Basic
mongoDB basic from:http://www.tutorialspoint.com/mongodb prject:https://github.com/chenxing12/l4mong ...
- python3初探
官方网站:https://www.python.org/ 类库大全:https://pypi.python.org/pypi 基础类库:https://docs.python.org/3/libr ...
- TOJ 1258 Very Simple Counting
Description Let f(n) be the number of factors of integer n. Your task is to count the number of i(1 ...
- ArrayList,LinkList,HashMap
ArrayList底层实现数组,这是ArrayList get()方法的源码,底层是数组 根据下标返回在数组中对应的位置 ,查询快,插入慢 // Positional Access Operation ...
- jQuery 文本插入和标签移动方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 10 个最佳的 Node.js 的 MVC 框架
补充:http://nokit.org/ https://thinkjs.org/zh-cn/doc/index.html Node.js 是一个基于Chrome JavaScript 运行时建立的一 ...
- C#博客记录一
前言:C#语言是由微软公司开发面向大众的一款软件开发语言. 1.c语音的输出语句为Console.Write();和Console.WriteLine(); 两者区别为后者为换行输出,前者不换行. 2 ...
- MVC类库视图在UI使用方法
在类库中固定文件:Controller Views 引用一下两个程序集(类库和UI项目都需要引用)(似乎只需要引用mvc的,build似乎在引用文件中不见了?有空测试一下) 如此方式,一个登录需要是 ...
- winform代码生成器(二)
代码下载 地址 http://pan.baidu.com/s/1nuZjyat 接着说 上文继续说,这次我们要生成主从表. 此方用到了第三方的 控件 DevExpress 的Gridview .大家可 ...