CF1265E Beautiful Mirrors (概率dp)

简介: CF1265E Beautiful Mirrors (概率dp)

原题链接

思路:

d p [ i ]表示走到第i ii个镜子的期望天数:

d p [ i ] = ( d p [ i − 1 ] + 1 ) ∗ p [ i ] + ( 1 − p [ i ] ) ∗ ( d p [ i − 1 ] + 1 + d p [ i ] )

当这个镜子说她漂亮时,只需要花费1天;

否则,需要从起点重新开始,也就是d p [ i ]

化简得:

1670379143993.png

其中

1670379114775.png

(x为输入的数)

注意求逆元的时候要用long long

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100,mod=998244353;
ll n,p[maxn],dp[maxn];
ll ksm(ll a,ll b){
  ll res=1;
  while(b){
    if(b&1) res=res*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return res;
}
int main(){
  ll n;cin>>n;  
  dp[0]=0;
  for(int i=1;i<=n;i++){
    cin>>p[i];
  }
  for(int i=1;i<=n;i++){
    dp[i]=(dp[i-1]+1)%mod*100%mod*ksm(p[i],mod-2)%mod;
  }
  cout<<dp[n]<<endl;
  return 0;
}


目录
相关文章
|
JavaScript 前端开发 Python
PIP常用命令-No module named ‘lxml‘
PIP常用命令-No module named ‘lxml‘
161 0
|
Linux Docker Windows
docker pull 报错解决:error pulling image configuration: Get https:..
docker pull 报错解决:error pulling image configuration: Get https:..
3998 0
|
7月前
|
Ubuntu Python
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
【Python】报错ModuleNotFoundError: No module named ‘XXX‘
|
7月前
|
Shell 计算机视觉 Python
no module named cv2 、numpy 、xxx超全解决方案
no module named cv2 、numpy 、xxx超全解决方案
|
缓存
Centos8使用yum报错 Couldn‘t resolve host name for http://mirrorlist.centos.org/?releas
Centos8使用yum报错 Couldn‘t resolve host name for http://mirrorlist.centos.org/?releas
1812 0
How to get text and corresponding tag with BeautifulSoup?
How to get text and corresponding tag with BeautifulSoup?
129 0
|
Python
ModuleNotFoundError: No module named ‘Image‘
ModuleNotFoundError: No module named ‘Image‘
389 0
ModuleNotFoundError: No module named ‘Image‘
|
Python
Python报错:ModuleNotFoundError:No module named 'xxx'
Python报错:ModuleNotFoundError: No module named 'xxx'
1127 2