zoukankan      html  css  js  c++  java
  • C. Two Arrays(组合数学,n个数选择m个数,单调不递减个数,排列组合打表N*N)

    题目链接:http://codeforces.com/problemset/problem/1288/C

    C. Two Arrays
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that:

    • the length of both arrays is equal to mm;
    • each element of each array is an integer between 11 and nn (inclusive);
    • aibiai≤bi for any index ii from 11 to mm;
    • array aa is sorted in non-descending order;
    • array bb is sorted in non-ascending order.

    As the result can be very large, you should print it modulo 109+7109+7.

    Input

    The only line contains two integers nn and mm (1n10001≤n≤1000, 1m101≤m≤10).

    Output

    Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.

    Examples
    input
    Copy
    2 2
    
    output
    Copy
    5
    
    input
    Copy
    10 1
    
    output
    Copy
    55
    
    input
    Copy
    723 9
    
    output
    Copy
    157557417
    
    Note

    In the first test there are 55 suitable arrays:

    • a=[1,1],b=[2,2]a=[1,1],b=[2,2];
    • a=[1,2],b=[2,2]a=[1,2],b=[2,2];
    • a=[2,2],b=[2,2]a=[2,2],b=[2,2];
    • a=[1,1],b=[2,1]a=[1,1],b=[2,1];
    • a=[1,1],b=[1,1]a=[1,1],b=[1,1].

    题目大意:

    给定一个数n和一个数m,让构建两个数组a和b满足条件,

    1.数组中所有元素的取值在1~n之间,a和b数组长度是m。2. a数组是单调不递减的,b数组是单调不递增 3. 任意的位置i,有ai<=bi

     问你有多少对这样的数组

    思路:

    从n个数中任选m个数,这m个数从小到大排列,且可重复选取的方案数为C(n+m-1,m)

     

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<vector>
    #include<stack>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long LL;
    #define sc1(a) scanf("%lld",&a)
    #define pf1(a) printf("%lld
    ",a)
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    const int INF=1e9+7;
    const int maxn=1e3+50;
    const int maxm=10+5;
    const int maxv=1e6+5;
    const int mod=1e9+7;
    const int ba=3e5;
    LL c[maxn][maxn];
    LL N,M;
    void Init()
    {
        for(int i=1;i<maxn;i++)//
        {
            for(int j=1;j<=i;j++)
            {
                if(j==1) c[i][j]=i;
                else
                {
                    c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
                }
            }
        }
    }
    int main()
    {
    //    freopen("in.txt","r",stdin);
        sc1(N);sc1(M);
        Init();
        LL ans=0,pre=0;
        for(int i=1;i<=N;i++) //从i个元素里选m个元素以i结尾 按非递减排列个数
        {
            ans=(ans+((c[i+M-1][M]-pre+mod)%mod)*(c[N-i+M][M])%mod)%mod;
            pre=c[i+M-1][M];//因为要以i结尾 所以减掉不是以i结尾的
        }
        pf1(ans);
        return 0;
    }
    /**
    
    */

     

     

    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    Redis源码解析:07压缩列表
    Redis源码解析:06整数集合
    Redis源码解析:05跳跃表
    Laravel中的路由管理
    jquery登录的异步验证
    ThinkPHP3.2.3中,配置文件里配置项的读取
    ThinkPHP3.2.3中,查询语句中in的使用方法。
    Fatal error: Maximum function nesting level of '100' reached, aborting!
    无限级分类的收缩与展开功能
    mysql添加DATETIME类型字段导致Invalid default value错误的问题
  • 原文地址:https://www.cnblogs.com/caijiaming/p/12257273.html
Copyright © 2011-2022 走看看