• 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
  • 相关阅读:
    JProfiler_SN_8_x key
    java格式化百分比
    获取每月第一天最后一天 java
    java 获取昨天日期
    eclipse git提交代码
    SIT与UAT的分别
    Spring <context:annotation-config/> 说明
    Hibernate日期映射类型
    Oracle查询备注信息
    Log4J入门
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14127827.html
Copyright © 2020-2023  润新知