ABC280e

· · 题解

算期望,考虑 dp。

设 f_i 表示打败血量为 i 怪兽的期望次数,p_1 表示打出一点伤害的概率,p_2 同理。

有 f_i = f_{i-1} \times p_1 + f_{i-2} \times p_2 + 1。

边界 f_0=0,f_1=1,注意取模。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5,mod=998244353;
int n,p1,p2,f[N];
int qpow(int x,int y=mod-2){
  int res=1;
  while(y){
    if(y&1)res=res*x%mod;
    x=x*x%mod;y>>=1;
  }
  return res;
}
signed main(){
  scanf("%lld%lld",&n,&p2);p2=p2*qpow(100)%mod;p1=(1+mod-p2)%mod;
  f[0]=0;f[1]=1;
  for(int i=2;i<=n;i++){
    f[i]=(f[i-1]*p1%mod+f[i-2]*p2%mod+1)%mod;
  }
  printf("%lld\n",f[n]);
  return 0;
}