zoukankan      html  css  js  c++  java
  • bzoj 1856: [Scoi2010]字符串 卡特兰数

    1856: [Scoi2010]字符串

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 1458  Solved: 814
    [Submit][Status][Discuss]

    Description

    lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数。现在lxhgww想要知道满足要求的字符串共有多少个,聪明的程序员们,你们能帮助他吗?

    Input

    输入数据是一行,包括2个数字n和m

    Output

    输出数据是一行,包括1个数字,表示满足要求的字符串数目,这个数可能会很大,只需输出这个数除以20100403的余数

    Sample Input

    2 2

    Sample Output

    2

    HINT

    【数据范围】
    对于30%的数据,保证1<=m<=n<=1000
    对于100%的数据,保证1<=m<=n<=1000000

    详见http://www.cnblogs.com/ezyzy/p/6532599.html

    证明一样

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #define ll long long
     6 #define N 2000005
     7 using namespace std;
     8 int n,m;
     9 int jie[N];
    10 const int p = 20100403;
    11 int pw(int x,int y)
    12 {
    13     ll lst=1;
    14     while(y)
    15     {
    16         if(y&1)lst=lst*x%p;
    17         y>>=1;
    18         x=(1LL*x*x)%p;
    19     }
    20     return lst;
    21 }
    22 int main()
    23 {
    24     scanf("%d%d",&n,&m);
    25     jie[0]=1;
    26     for(int i=1;i<=n+m;i++)jie[i]=(1LL*jie[i-1]*i)%p;
    27     ll ans=1LL*jie[n+m]*pw(jie[n],p-2)%p*pw(jie[m],p-2)%p-1LL*jie[n+m]*pw(jie[n+1],p-2)%p*pw(jie[m-1],p-2)%p;
    28     ans=(ans+p)%p;
    29     printf("%lld
    ",ans);
    30     return 0;
    31 }
  • 相关阅读:
    Eclipse的tomcat插件
    sql优化:
    ecipse theme
    load()和get()的区别
    eclipse手动指定启动的jdk版本
    TOD&FIXME&XXX
    命令式和声明式
    显示器调色温
    jdeveloper优化:
    win7 登录后只能使用“临时配置文件”,原来的配置文件无法启用!
  • 原文地址:https://www.cnblogs.com/ezyzy/p/6532658.html
Copyright © 2011-2022 走看看