题目大意:
长度为n+1的序列A,其中的每个数都是不大于n的正整数,且n以内每个正整数至少出现一次。
对于每一个正整数k=1,…,n+1,求出的本质不同的长度为k的子序列(不一定要连续)的数量。对109+7取模。
思路:
这题思路还是很好想的,先算出n+1个数的子序列数量,然后剪掉重复的数量就好了,重复的数量很好算,就只和两个相同的字符的位置有关,然后就AC了。
程序:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#define N 100005
#define LL long long
using namespace std;
const LL mo=1e9+7;
LL ans,jc[N],ny[N];
LL n,h[N],a,b,x;
LL mul(LL x,LL y){
LL o=1;
while (y){
if (y%2==1) o=(o*x)%mo;
x=(x*x)%mo;
y=y/2;
}
return o;
}
LL c(LL x,LL y){
if (y==0) return 1;
if (y>x) return 0;
LL o=jc[x]*ny[y]%mo;
return o*ny[x-y]%mo;
}
int main(){
scanf("%lld",&n);
n++;
for (LL i=1;i<=n;i++){
scanf("%lld",&x);
if (h[x]) a=h[x],b=i;
h[x]=i;
}
jc[0]=1; ny[0]=1;
for (LL i=1;i<=n;i++)
jc[i]=jc[i-1]*i%mo,ny[i]=mul(jc[i],mo-2);
for (LL i=1;i<=n;i++){
ans=(c(n,i)-c(n-b+a-1,i-1)+mo)%mo;
printf("%lld\n",ans);
}
}