CF1278F Cards 题解 / 上升下降普通幂转换
题目传送门:CF1278F Cards。
直接推式子,令 \(p=\frac{1}{m}\) 即抽到 joker 的概率。
\[\begin{aligned}
ans&= \sum_{x=0}^n p^x(1-p)^x x^k {n\choose x} \\
&= \sum_{x=0}^n \sum_{y=0}^k {k\brace y} x^{\underline y} p^x(1-p)^{n-x}{n\choose x}\\
&= \sum_{x=0}^n \sum_{y=0}^k p^x(1-p)^{n-x}{n-y\choose x-y}n^{\underline y}{k\brace y}\\
&= \sum_{y=0}^k n^{\underline y} {k\brace y} \sum_{x=0}^n p^x(1-p)^{n-x} {n-y\choose x-y}\\
&= \sum_{y=0}^k n^{\underline y} {k\brace y} \sum_{x=0}^{n-y} p^{x+y} (1-p)^{n-y-x} {n-y\choose x-y}\\
&= \sum_{y=0}^k n^{\underline y} {k\brace y} p^y \sum_{x=0}^{n-y} p^{x} (1-p)^{n-y-x} {n-y\choose x-y} \\
&= \sum_{y=0}^k n^{\underline y} {k\brace y} p^y (p+1-p)^{n-y} \\
&= \sum_{y=0}^k n^{\underline y} {k\brace y} p^y
\end{aligned}
\]
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
inline int read(){
char c=getchar();
int f=1,ans=0;
while(c<48||c>57) f=(c==45?f=-1:1),c=getchar();
while(c>=48&&c<=57) ans=(ans<<1)+(ans<<3)+(c^48),c=getchar();
return ans*f;
}
const int N=5010,mod=998244353;
int s[N][N],n,m,k,p,f[N];
inline void exgcd(int a,int b,int &x,int &y){
if (b==0) x=1,y=0;
else exgcd(b,a%b,y,x),y-=a/b*x;
}
inline int inv(int a){int x,y;exgcd(a,mod,x,y);return (x%mod+mod)%mod;}
inline int qpow(int a,int b){
int s=1;
while(b) ((b&1)?s=s*a%mod:1),a=a*a%mod,b>>=1;
return s;
}
main(){
n=read(),m=read(),k=read(),p=inv(m);
s[0][0]=1;
for (int i=1;i<=k;i++) for (int j=1;j<=i;j++) s[i][j]=(s[i-1][j]*j%mod+s[i-1][j-1])%mod;
f[0]=1;for (int i=1;i<=k;i++) f[i]=f[i-1]*(n-i+1)%mod;
int ans=0;
for (int i=0;i<=k;i++) ans=(ans+f[i]*s[k][i]%mod*qpow(p,i)%mod)%mod;
cout <<ans;
return 0;
}

浙公网安备 33010602011771号