ABC326E 题解
Binary_Lee · · 题解
题面传送门
解决思路
套路地,我们讨论每个数字对于最终答案的贡献。
以四个数 1 2 3 4 为例:
首先是他们第一次就被选到的概率,显然都为
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| 第 1 次 |
然后考虑第二次的贡献:
-
-
2$ 产生贡献前提是上一次选到了 $1$,然后这次选到 $2$。故概率是 $\frac14\times\frac14=\frac{1}{4^2} -
3$ 产生贡献前提是上一次选到了 $1$ 或 $2$,然后这次选到 $3$。故概率是 $(\frac14+\frac14)\times\frac14=\frac{2}{4^2} -
4$ 产生贡献前提是上一次选到了 $1$ 或 $2$ 或 $3$,然后这次选到 $4$。故概率是 $(\frac14+\frac14+\frac14)\times\frac14=\frac{3}{4^2}
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| 第 1 次 | ||||
| 第 2 次 |
同理考虑第三次的贡献:
-
-
3$ 产生贡献前提是上一次选到了 $1$ 或 $2$,然后这次选到 $3$。故概率是 $(0+\frac{1}{4^2})\times\frac14=\frac{1}{4^3} -
4$ 产生贡献前提是上一次选到了 $1$ 或 $2$ 或 $3$,然后这次选到 $4$。故概率是 $(0+\frac{1}{4^2}+\frac{2}{4^2})\times\frac14=\frac{3}{4^3}
第四次概率也同理。
所以我们得到最终表格:
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| 第 1 次 | ||||
| 第 2 次 | ||||
| 第 3 次 | 0 | |||
| 第 4 次 | 0 | 0 |
发现了什么?第
我们设第
然后问题就解决了。
AC Code
//If, one day, I finally manage to make my dreams a reality...
//I wonder, will you still be there by my side?
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(0),cout.tie(0)
#define int long long
#define y1 cyy
#define fi first
#define se second
#define cnt1(x) __builtin_popcount(x)
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lbt(x) (x&(-x))
#define mod 998244353
using namespace std;
int n,a[300005],p,ans,f[300005];
int ksm(int x,int b){
int ans=1;
while(b){
if(b&1) ans=ans*x%mod;
x=x*x%mod,b>>=1;
}
return ans;
}
signed main(){
IOS;TIE;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int INV=ksm(n,mod-2);
f[1]=INV;
ans+=f[1]*a[1]%mod;
for(int i=2;i<=n;i++){
f[i]=f[i-1]+f[i-1]*INV%mod,f[i]%=mod;
ans+=a[i]*f[i]%mod;
ans%=mod;
}
cout<<ans<<endl;
return 0;
}