题意:
要从 1 1 1走到 n n n,每次成功走下去的概率为 p i 100 \frac{p_i}{100} 100pi,如果不成功那就回到 1 1 1号点继续走。问走完 n n n个点的期望是多少。
思路:
以前见过这种失败了就回到起点的期望 d p dp dp,但还是想了很久。
考虑 f [ i ] f[i] f[i]表示到当前点的期望步数。如果成功了的话,那就是直接从 f [ i − 1 ] f[i-1] f[i−1]转移过来就行。如果失败了的话,那就是从 i − 1 i-1 i−1走过来,但是回到了起点,再加上到 i i i点的期望就行啦,写成 d p dp dp方程的形式是这样的: f [ i ] = ( f [ i − 1 ] + 1 ) ∗ p i 100 + ( f [ i − 1 ] + f [ i ] + 1 ) ∗ 100 − p i 100 f[i]=(f[i-1]+1)*\frac{p_i}{100}+(f[i-1]+f[i]+1)*\frac{100-p_i}{100} f[i]=(f[i−1]+1)∗100pi+(f[i−1]+f[i]+1)∗100100−pi化简一下就是 f [ i ] = 100 ∗ ( 1 + f [ i − 1 ] ) p [ i ] f[i]=\frac{100*(1+f[i-1])}{p[i]} f[i]=p[i]100∗(1+f[i−1])用快速幂求逆元就行啦。
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=998244353,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
LL p[N],f[N];
LL qmi(LL a,LL b)
{
LL ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans%mod;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lld",&p[i]);
for(int i=1;i<=n;i++) f[i]=100*(1+f[i-1])%mod*qmi(p[i],mod-2)%mod;
printf("%lld\n",f[n]%mod);
return 0;
}
/*
*/