codeforce 891 E
资瓷,日常不打数学公式,扔个链接:传送门
扔个trick,生成函数的X可以是多项式,而且可以连续域的卷积。(平时的fft是离散的。)
狄雷克卷积可不可以我不知道,有大佬知道请告诉我一下。
#include<bits/stdc++.h> #define N 5005 #define sight(x) ('0'<=x&&x<='9') #define mo 1000000007 using namespace std; #define LL long long int n,K,m,ans,a[N],f[N][N]; inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } void write(int x){if (x<10) {putchar('0'+x); return;} write(x/10); putchar('0'+x%10);} inline void writeln(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar('\n'); } inline void writel(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar(' '); } LL qsm(LL x,int y){ static LL anw; for (anw=1;y;y>>=1,x=x*x%mo) if (y&1) anw=anw*x%mo; return anw; } int main(){ read(n); read(K); for (int i=1;i<=n;i++) read(a[i]); f[0][0]=1; for (int i=1;i<=n;i++){ f[i][0]=(LL)f[i-1][0]*a[i]%mo; for (int j=1;j<=i;j++) f[i][j]=((LL)f[i-1][j]*a[i]-f[i-1][j-1])%mo; } for (int i=0;i<=min(n,K);i++){ int calc=1; for (int j=K-i+1;j<=K;j++) calc=(LL)calc*j%mo; ans=(ans+(LL)f[n][i]*qsm(n,K-i)%mo*calc)%mo; } ans=(LL)ans*qsm(qsm(n,K),mo-2)%mo; m=1; for (int i=1;i<=n;i++) m=(LL)m*a[i]%mo; ans=(m-ans)%mo; if (ans<0) ans+=mo; writeln(ans); return 0; }