问题 C: 11

问题 C: 11

时间限制: 1 Sec  内存限制: 128 MB
提交: 111  解决: 35
[提交] [状态] [讨论版] [命题人:admin]

题目描述

You are given an integer sequence of length n+1, a1,a2,…,an+1, which consists of the n integers 1,…,n. It is known that each of the n integers 1,…,n appears at least once in this sequence.
For each integer k=1,…,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 109+7.
Notes
If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.
A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

Constraints
1≤n≤105
1≤ai≤n
Each of the integers 1,…,n appears in the sequence.
n and ai are integers.

 

 

输入

Input is given from Standard Input in the following format:
n
a1 a2 ... an+1

 

输出

Print n+1 lines. The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 109+7.

 

样例输入

3
1 2 1 3

 

样例输出

3
5
4
1

 

提示

There are three subsequences with length 1: 1 and 2 and 3.
There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.
There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.
There is one subsequence with length 4: 1,2,1,3.

 

 

排列组合题,假设这样。如下--+--+--(+代表重复的那两个数)

---------------------+--------------------------+--------------------------

若取k个数那么有C(n+1,k)种取法,去掉重复的即可

如果在第一个+前取k-1个那么最后一个取第一个+和第二个+便重复了,重复的取法有C(i1-1,k-1)种

如果在第二个+后面取k-1种,同样第一个会重复C(n+1-i2,k-1)种,实际上不止这样

在前后两个+之外的区域取k-1种都会使得重复

所以答案为C(n+1,k)-C(n+i1-i2,k-1)种

排列数模板       这儿、

代码

#include<bits/stdc++.h>
#define ll long long
#define mod (ll)(1e9+7)
using namespace std;
ll a[100005];
ll Pow(ll a,ll b){
    a%=mod;
    ll ans = 1;
    while(b)
    {
        if(b&1)
            ans = (ans*a)%mod;
        a = (a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
ll Quk(ll a,ll b){
    a%=mod;
    ll ans = 0;
    while(b)
    {
        if(b&1)
            ans = (ans+a)%mod;
        a = (a+a)%mod;
        b/=2;
    }
    return ans%mod;
}
ll C(ll n,ll m){
    if(n<m)return 0;
    return Quk(Quk(a[n],Pow(a[n-m],mod-2)),Pow(a[m],mod-2))%mod;
}
int v[100005];
int c[100005];
int main()
{
    a[0]=a[1]=1;
    for(ll i=2;i<=100002;i++)
        a[i]=Quk(a[i-1],i);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++)
        scanf("%d",&c[i]),v[c[i]]++;
    int i1,i2;
    i1=i2=0;
    for(int i=1;i<=n+1;i++)
    {
        if(v[c[i]]==2 && !i1)
            i1=i;
        else if(v[c[i]]==2)
            i2=i;
    }
    ll ans = 0;
    for(ll i=0;i<=n;i++)
    {
        ans = C((ll)n+1,i+1);

        ans -= C((ll)n+i1-i2,i);

        printf("%lld\n",ans>=0?ans:ans+mod);
    }

    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值