luogu P6620 [省选联考 2020 A 卷] 组合数问题
题面传送门
直接对着这个式子是真的不好做,考虑把它转化成下降幂多项式。
设原来的多项式是\(f(x)=\sum\limits_{i=0}^{m}{a_ix^i}\),现在的多项式是\(g(x)=\sum\limits_{i=0}^{m}{b_ix^{\underline{i}}}\)
然后原式转化成这个样子:\(\sum\limits_{k=0}^{n}{x^k\sum\limits_{i=0}^{m}{b_i\times \frac{n!}{(n-k)!(k-i)!}}}\)
可以把里面配成广义二项式定理的亚子:\(\sum\limits_{k=0}^{n}{x^k\sum\limits_{i=0}^{m}{b_i\times n^{\underline{i}}\times C_{n-i}^{k-i}}}\)
交换求和号变成\(\sum\limits_{i=0}^{m}{b_i\times x^{i}\times n^{\underline{i}}\sum\limits_{k=0}^{n}{C_{n-i}^{k-i}x^{k-i}}}\)
就变成\(\sum\limits_{i=0}^{m}{b_i\times x_{i}\times n^{\underline{i}}\times (x+1)^{n-i}}\)
所以问题在于求\(b\)
可以考虑斯特林反演\(x^{n}=\sum\limits_{i=0}^{n}{x^{\underline{i}}S(n,i)}\)
然后\(O(m^2)\)暴力递推即可。
code:
#include<bits/stdc++.h>
#define I inline
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define re register
#define RI re int
#define ll long long
#define db double
#define lb long db
#define N (1000+5)
#define M (1<<23)+5
#define mod 1000000007
#define Mod (mod-1)
#define eps (1e-9)
#define U unsigned int
#define it iterator
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) (n*(x-1)+(y))
#define R(n) (rand()*rand()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using namespace std;
int n,m,p,x;ll ToT,A[N+5],B[N+5],Ans,S[N+5][N+5];
I ll mpow(ll x,int y){ll Ans=1;while(y) y&1&&(Ans=Ans*x%p),y>>=1,x=x*x%p;return Ans;}
int main(){
freopen("1.in","r",stdin);
RI i,j;scanf("%d%d%d%d",&n,&x,&p,&m);for(i=0;i<=m;i++)scanf("%lld",&A[i]);
S[0][0]=1;for(i=1;i<=m;i++) for(j=1;j<=m;j++) S[i][j]=(S[i-1][j-1]+S[i-1][j]*j)%p;
for(i=0;i<=m;i++) for(j=i;j<=m;j++) B[i]=(B[i]+A[j]*S[j][i])%p;
ToT=1;for(i=0;i<=m;i++) Ans+=ToT*B[i]%p*mpow(x,i)%p*mpow(x+1,n-i)%p,ToT=ToT*(n-i)%p;printf("%lld\n",Ans%p);
}