解析:
也可以将所有的可能都计算出来,后进行减法运算。
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long #define rint register int inline int read(){ int x=0,f=0;char ch=getchar(); while(!isdigit(ch)) f=(ch==45),ch=getchar(); while( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return f?(~x+1):x; } const ll md=1e9+7; #define man 100050 int n; long long fac[man],inv[man]; int x,y,xx,yy,a[man],v[man]; inline long long bpow(long long a,int b){ long long ans=1;a%=md; while(b){ if(b&1) ans=ans*a%md; a=a*a%md; b>>=1; } return ans; } inline ll C(ll nn,ll mm){ ll ret=fac[nn]*inv[mm]%md*inv[nn-mm]%md; return ret%md; } int main(){ n=read(); memset(v,0,sizeof(v)); for(rint i=1;i<=n+1;i++){ scanf("%d",&a[i]); if(v[a[i]]!=0) xx=v[a[i]],yy=i; if(v[a[i]]==0) v[a[i]]=i; } x=xx-1;y=n+1-yy; fac[0]=inv[0]=1; for(rint i=1;i<=n+1;i++) fac[i]=fac[i-1]*i%md,inv[i]=bpow(fac[i],md-2); printf("%d ",n); for(rint i=2;i<=n;i++){ ll ans=0; if(x+y>=i-1) ans=(C(n+1,i)-C(x+y,i-1)+md)%md; else ans=C(n+1,i)%md; while(ans<0) ans=(ans+md)%md; printf("%lld ",ans); } printf("1 "); return 0; }