CF1265E Solution
题解在说啥???
期望步数不就是期望轮数乘上每轮的期望步数
期望轮数就是这轮结束的概率的倒数即 \(\dfrac1{\prod_{i=1}^np_i}\)
每轮期望步数根据期望的线性性就是 \(\sum_{i=1}^ni(1-p_i)\prod_{j=1}^{i-1}p_j\)
也就是步数乘上在这里停下来的概率,停下来的概率就是此处不通过,前面全通过的概率相乘。
期望步数还要加上一个 \(n\prod_{i=1}^np_i\),就是到达终点的步数
#include <bits/stdc++.h>
#define LL long long
#define sl(n) strlen(n)
#define endline puts("")
#define pii pair<int , int>
#define pr_q priority_queue
#define DEBUG puts("DEBUG.")
using namespace std;
const int N = 2e5 + 10;
const int inf = ~0u >> 2;
const int p = 998244353;
int qpow(int a , int k)
{
int res = 1;
while(k)
{
if(k & 1)
res = 1ll * res * a % p;
a = 1ll * a * a % p;
k >>= 1;
}
return res;
}
const int inv100 = qpow(100 , p - 2);
int n,pp[N],prd[N];
int main()
{
cin >> n;
prd[0] = 1;
for(int i = 1;i <= n;i++)
scanf("%d" , pp + i),pp[i] = 1ll * pp[i] * inv100 % p,prd[i] = 1ll * prd[i - 1] * pp[i] % p;
int round = qpow(prd[n] , p - 2);
int step = 0;
for(int i = 1;i <= n;i++)
step = (step + 1ll * i * prd[i - 1] % p * (1 - pp[i] + p) % p) % p;
step = (step + 1ll * n * prd[n] % p) % p;
cout << 1ll * round * step % p << endl;
return 0;
}
标签:期望,int,cf1265e,solution,res,const,步数,define
From: https://www.cnblogs.com/iorit/p/18040094