hdu6267 Master of Random(期望)

 

 

hdu6267 Master of Random(期望)

hdu6267 Master of Random(期望)

比赛的时候是队友推的。但是赛后想了想这种题找到方向了,就不该推那么长时间。

思路:

一看,所有情况都枚举一遍显然是不合理的 。那么我就去转化思维,想每一个点对总答案的贡献。(很多题都是这个想法。)

推导过程:

hdu6267 Master of Random(期望)

还要乘以权值。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL quick(LL a,LL b){
    LL ans=1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
LL inv(LL x){
    return quick(x,mod-2);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        LL tp=1;
        for(int i=1;i<n;i++){
            tp=(tp*i)%mod;///计算(n-1)!
        }
        LL a,tmp=tp;
        scanf("%lld",&a);
        LL ans=tp*a%mod;
        for(int i=1;i<n;i++){
            scanf("%lld",&a);
            tmp=tmp+tp*inv(i)%mod;
            ans=(ans+tmp*a)%mod;
        }
        tp=tp*n%mod;
        printf("%lld\n",ans*inv(tp)%mod);
    }
    return 0;
}

 

相关文章:

  • 2021-12-31
  • 2022-12-23
  • 2021-12-09
  • 2021-11-20
猜你喜欢
  • 2021-11-12
  • 2021-12-20
  • 2021-11-30
  • 2021-12-15
  • 2022-02-18
  • 2021-08-02
相关资源
相似解决方案