zoukankan      html  css  js  c++  java
  • BZOJ 1856: [Scoi2010]字符串( 组合数 )

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

    ------------------------------------------------------------------

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
     
    using namespace std;
     
    typedef long long ll;
     
    const int MOD = 20100403;
    const int maxn = 2000009;
     
    int N, M, fac[maxn];
     
    void gcd(int a, int b, int &d, int &x, int &y) {
    if(!b) {
    d = a; x = 1; y = 0;
    } else {
    gcd(b, a % b, d, y, x);
    y -= x * (a / b);
    }
    }
     
    int inv(int m) {
    int d, x, y; gcd(m, MOD, d, x, y);
    return (x + MOD) % MOD;
    }
     
    void init() {
    fac[0] = 1;
    for(int i = 1; i <= N + M; i++)
    fac[i] = ll(i) * fac[i - 1] % MOD;
    }
     
    int C(int m, int n) {
    return ll(fac[n]) * inv(fac[m]) % MOD * inv(fac[n - m]) % MOD;
    }
     
    int main() {
    scanf("%d%d", &N, &M); init();
    printf("%d ", (C(N, N + M) - C(M - 1, N + M) + MOD) % MOD);
    return 0;
    }

    ------------------------------------------------------------------

    1856: [Scoi2010]字符串

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 1083  Solved: 573
    [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

    Source

  • 相关阅读:
    SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问
    谷歌浏览器扩展程序manifest.json参数详解
    获取天气api
    UVA 10385 Duathlon
    UVA 10668 Expanding Rods
    UVALIVE 3891 The Teacher's Side of Math
    UVA 11149 Power of Matrix
    UVA 10655 Contemplation! Algebra
    UVA 11210 Chinese Mahjong
    UVA 11384 Help is needed for Dexter
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4908900.html
Copyright © 2011-2022 走看看