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
  • 相关阅读:
    python中字典一键多相同值反转技巧
    win10下安装mysql
    上台阶问题的具体走法用python来实现
    桥接模式
    适配器模式
    多线程中lock的使用
    原型模式
    多线程
    建造者模式
    代理模式
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14127827.html
Copyright © 2011-2022 走看看