zoukankan      html  css  js  c++  java
  • CF57C Array

    Description

    Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of $ n $ , containing only integers from $ 1 $ to $ n $ . He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions:

    - each elements, starting from the second one, is no more than the preceding one
    - each element, starting from the second one, is no less than the preceding one

    Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last.

    Solution

    设集合$S={a_1,a_2,cdots,a_n}$表示每一个数的出现次数,那么每一个$S$与$A$唯一对应,每一个不增序列与一个不降序列唯一对应(常序列除外)

    因为$sum_{i=1}^n a_i=n$,问题转化为$n$个$1$的插板方案数(允许$0$)

    答案为$inom {2n}{n}-n$

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int n;
    long long fac[200005]={1},inv[200005];
    const long long mod=1e9+7;
    inline int read()
    {
        int f=1,w=0;
        char ch=0;
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') w=(w<<1)+(w<<3)+ch-'0',ch=getchar();
        return f*w;
    }
    long long ksm(long long a,long long p)
    {
        long long ret=1;
        while(p)
        {
            if(p&1) (ret*=a)%=mod;
            (a*=a)%=mod,p>>=1;
        }
        return ret;
    }
    int main()
    {
        n=read();
        for(int i=1;i<=2*n;i++) fac[i]=fac[i-1]*i%mod;
        inv[2*n]=ksm(fac[2*n],mod-2);
        for(int i=2*n-1;~i;i--) inv[i]=inv[i+1]*(i+1)%mod;
        printf("%lld
    ",(fac[2*n]*inv[n]%mod*inv[n]%mod-n+mod)%mod);
        return 0;
    }
    Array
  • 相关阅读:
    vue bus 中央事件总线
    0时间复杂度
    stack 数据结构
    es6 class
    directives 自定义指令
    node中间件
    数据结构博客清单
    TCP/IP 协议栈博客清单
    Java 面向对象:接口
    Java 面向对象:Object 类
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14127827.html
Copyright © 2011-2022 走看看