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

  • 相关阅读:
    Leetcode Binary Tree Preorder Traversal
    Leetcode Minimum Depth of Binary Tree
    Leetcode 148. Sort List
    Leetcode 61. Rotate List
    Leetcode 86. Partition List
    Leetcode 21. Merge Two Sorted Lists
    Leetcode 143. Reorder List
    J2EE项目应用开发过程中的易错点
    JNDI初认识
    奔腾的代码
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4908900.html
Copyright © 2011-2022 走看看