zoukankan      html  css  js  c++  java
  • Two Arrays CodeForces

    题目链接: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

     问你有多少对这样的数组

    思路:一直在想组合数学怎么做,感觉很麻烦,很多种情况,就没写了。 dp其实可以做

    a数组是单调不递减 b数组是单调不递增 ,如果我们把b数组反过来呢 接在a数组的后面,我们会得到一个长度为2*M的单调不递减的数组

    是的,那么我们只要求长度为2*M的单调不递减的数组就行了

    得到状态转移方程:

    dp[i][j]表示第i个位置可以放 大于等于 j 的方案数 ,那么转移方程就是 dp[i][j] = dp[i-1][j] + dp[i][j+1]

    看代码:

    #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+5;
    const int maxm=10+5;
    const int maxv=1e6+5;
    const int mod=1e9+7;
    const int ba=3e5;
    LL dp[maxm<<1][maxn];
    int main()
    {
    //    freopen("in.txt","r",stdin);
        LL N,M;sc1(N);sc1(M);
        for(int i=1;i<=N;i++) dp[1][i]=1;
        for(int i=2;i<=M*2;i++)
        {
            for(int j=N;j>=1;j--)
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j+1])%mod;
            }
        }
        LL ans=0;
        for(int i=1;i<=N;i++) ans=(ans+dp[2*M][i])%mod;
        pf1(ans);
        return 0;
    }
    /**
    
    */
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    获取某个文件夹下面的子文件夹(要求是第一级)
    操作手册
    GWT与GXT
    eclipse中出现:The project cannot be built until build path errors are resolved
    eclipse部署项目要做的工作及配置
    如何测试tomcat安装成功
    tomcat的安装及eclipse配置
    配置jdk
    oracle数据库的安装、完全卸载与plsql的安装以及与oracle的连接
    UVA
  • 原文地址:https://www.cnblogs.com/caijiaming/p/12256489.html
Copyright © 2011-2022 走看看