思路:

设1为向(1,1)方向走,0为向(1,-1)方向走。那么题意可转化为从(0,0)走到(n+m,n-m)且不能跨过y=0的方案数。总方案数C(n+m,n),然后要减去不合法的即线路通过y=-1的。将线路与y=-1交点的左边沿着y=-1做对称操作,则最后等价于从(0,-2)走到(n+m,n-m)的方案数。因为从(0,-2)

走到(n+m,n-m)需要向上走n-m+2次,一共要走n+m次。设向上向下各走x,y,那么x+y=n+m,x-y=n-m+2得到x=n+1,y=m-1,所以不合法的方案为C(n+m,m-1)。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=;
const int N=;
int n,m,ans,f[][N][N];
void dp(){
// f[n+m][n][m]=1;
int now=;
f[now][n][m]=;
for(int i=n+m-;~i;i--){
now^=;
for(int j=;j<=n;j++){
for(int k=;k<=m;k++){
if(j>k&&k<m) f[now][j][k]+=f[now^][j][k+];
if(j<n) f[now][j][k]+=f[now^][j+][k];
if(f[now][j][k]>=mod) f[now][j][k]-=mod;
}
}
}
printf("%d\n",f[now][][]);
}
int main(){
freopen("string.in","r",stdin);
freopen("string.out","w",stdout);
cin>>n>>m;
if(n<m){puts("");return ;}
dp();
return ;
}

10分dp

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=;
const int N=1e5+;
int n,m,ans,f[][N];
void dp(){
int now=;
f[][]=;
for(int i=;i<=n;i++){
now^=;
for(int j=;j<=min(i,m);j++){
if(i) f[now][j]+=f[now^][j];
if(j) f[now][j]+=f[now][j-];
if(f[now][j]>=mod) f[now][j]-=mod;
}
for(int j=;j<=min(i,m);j++) f[now^][j]=;
}
printf("%d\n",f[now][m]);
}
int main(){
freopen("string.in","r",stdin);
freopen("string.out","w",stdout);
cin>>n>>m;
if(n<m){puts("");return ;}
dp();
return ;
}

30分dp

//ans=C(n+m,n)-C(n+m,m-1){来源折线定理}
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=2e6+;
const ll mod=;
int n,m;ll ans,fz[N],fm[N];
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
if(!b){d=a;x=;y=;return ;}
exgcd(b,a%b,d,y,x);
y-=a/b*x;
}
ll inv(ll a,ll p){
ll d,x,y;
exgcd(a,p,d,x,y);
return d==?(x%p+p)%p:-;
}
int main(){
cin>>n>>m;
int S=n+m;fz[]=fm[]=;
for(ll i=;i<=S;i++) fz[i]=(fz[i-]*i)%mod;
fm[S]=inv(fz[S],mod);
for(ll i=S-;i;i--) fm[i]=(fm[i+]*(i+))%mod;
ans=(fz[n+m]*fm[n]%mod*fm[m]%mod-fz[n+m]*fm[m-]%mod*fm[n+]%mod+mod)%mod;
cout<<ans;
}

[SCOI2010]字符串的更多相关文章

  1. Bzoj 1856: [Scoi2010]字符串 卡特兰数,乘法逆元,组合数,数论

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1194  Solved: 651[Submit][Status][ ...

  2. BZOJ 1856: [Scoi2010]字符串( 组合数 )

    求(0,0)->(n,m)且在直线y=x下方(可以在y=x上)的方案数...同 http://www.cnblogs.com/JSZX11556/p/4908648.html --------- ...

  3. 1856: [Scoi2010]字符串

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 847  Solved: 434[Submit][Status] D ...

  4. BZOJ 1856: [Scoi2010]字符串 [Catalan数]

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1418  Solved: 790[Submit][Status][ ...

  5. 【BZOJ1856】[SCOI2010]字符串(组合数学)

    [BZOJ1856][SCOI2010]字符串(组合数学) 题面 BZOJ 洛谷 题解 把放一个\(1\)看做在平面直角坐标系上沿着\(x\)正半轴走一步,放一个\(0\)看做往\(y\)轴正半轴走一 ...

  6. bzoj 1856: [Scoi2010]字符串 卡特兰数

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1458  Solved: 814[Submit][Status][ ...

  7. 1856: [Scoi2010]字符串(Catalan数)

    1856: [Scoi2010]字符串 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 2117  Solved: 1211[Submit][Status] ...

  8. BZOJ1856[SCOI2010]字符串

    Description lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgw ...

  9. 【BZOJ】1856: [Scoi2010]字符串

    http://www.lydsy.com/JudgeOnline/problem.php?id=1856 题意:把n个1和m个0组成字符串,要求在组成的字符串中,任意的前k个字符1的个数不能少于0的个 ...

  10. BZOJ1856 [Scoi2010]字符串 数论

    原文链接http://www.cnblogs.com/zhouzhendong/p/8084577.html 题目传送门 - BZOJ1856 题意概括 找出由n个1,m个0组成的字符串,且任意前几个 ...

随机推荐

  1. Android的xml/assets/raw资源使用具体解释

    一.assets/xml/raw资源介绍 1.assets资源文件夹:assets文件夹下存放的资源代表应用无法直接訪问的原生资源,这些文件将原封不动的存储到设备上,不会被编译为二进制形式,訪问方式是 ...

  2. EntityFramework Data Annotations

    详细的实体映射介绍(Data Annotation) http://msdn.microsoft.com/en-us/data/jj591583

  3. jQuery knowledge

    I have used jquery for many years, but didn't list the problem I ever meeting, so here is a list of ...

  4. Linux下从视频提取音频的方法

    Linux下可以利用mencoder将视频里的音频提取出来.方法如下: 1.首先安装mencoder.对于Ubuntu来说,软件仓库里就有mencoder,可直接输入如下命令安装 sudo apt-g ...

  5. Lambda编写斐波那契数列

    还需要考虑溢出等问题,闲来无事写了写 Func<float, float, float> a = (arg1, arg2) => 0f;//init ; a = (lastNumbe ...

  6. verilog gtkwave

    gtkwave,开源波形显示软件 来自 bluesky1 博客.http://blog.sina.com.cn/s/blog_566ca6330100c0t3.html~type=v5_one& ...

  7. IOS委托,实现两个UIView相互传值

    转自:http://my.oschina.net/wbei/blog/89325 detegate委托在IOS中是一种随处可见的模式,通俗的说,就是我把想做的某件事委托给其他人去做,就好像Java中的 ...

  8. JS 遍历 json key ,获取设置可变的key

    $(rec.data[id]).each(function(){ for(var key in this){ if(key == value){ console.info(this[key].desc ...

  9. nginx+keeplived负载均衡配置

    一.nginx 编译安装 1.依赖环境安装     yum -y install gcc gcc-c++ zlib zlib-devel pcre pcre-devel openssl openssl ...

  10. Scala类中的get与set

    在scala类中get和set使用有以下几种: 1. var foo: Scala自动合成一个getter和一个setter 2. val foo: Scala自动合成一个getter scala中v ...