题目链接:https://atcoder.jp/contests/abc295/tasks/abc295_e
一道数学好题,做完后深受启发。
思路:设\(A_k\)处的值为\(x\),则答案为:\(E(x) = \Sigma_1^m i*p(x = i) = 1*p(x=1)+2*p(x=2)+....+m*p(x=m) = p(x>=1)+p(x>=2)+...+p(x>=m) = \Sigma_1^m p(x>=i)\)。
接着枚举\(i\),运用组合数学的知识求解。
代码(c++):
#include<bits/stdc++.h>
using namespace std;
const int N = 2010,mod = 998244353;
int num[N];
long long c[N][N];
long long qmod(long long x,long long y){
long long ans = 1;
while(y){
if (y&1) ans = ans*x%mod;
y = y>>1;
x = x*x%mod;
}
return ans;
}
int main(){
int n,m,k;
cin>>n>>m>>k;
c[0][0] = 1;
for (int i=1;i<=2000;i++){
c[i][0] = 1;
for (int j=1;j<=i;j++){
c[i][j] = (c[i-1][j-1]+c[i-1][j])%mod;
}
}
for (int i=1;i<=n;i++) cin>>num[i];
long long ans = 0;
for (int i=1;i<=m;i++){
int z = 0,mx = 0;
for (int j=1;j<=n;j++){
if (!num[j]) z++;
else if (num[j]>=i) mx++;
}
long long p1 = (m-i+1)*qmod(m,mod-2)%mod;
long long p2 = (i-1)*qmod(m,mod-2)%mod;
long long q = 0;
for (int h=max(0,n-k+1-mx);h<=z;h++){
q = (q+c[z][h]*qmod(p1,h)%mod*qmod(p2,z-h)%mod)%mod;
}
ans = (ans+q)%mod;
}
cout<<ans<<'\n';
}
标签:int,long,ans,mod,abc295,qmod
From: https://www.cnblogs.com/xjwrr/p/17268023.html