Codeforces Round 604 (Div. 2) D 期望dp

题目链接

从1开始遍历,有ai/100的概率进入下一个下标

100-ai/100的概率从头开始

问多少次可以到达n+1

设dp[i]为从i-1到达i的期望次数

dp方程为下

在这里插入图片描述

sum是从1到达i-1的期望步数

然后都算出来之后我们都加起来就好了

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
#define int long long
const int INF = 4e18+5;
#define F(i,l,r) for(int i=l;i<=r;i++)
#define R(i,l,r) for(int i=r;i>=l;i--)
#define vv vector
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
const int mod = 998244353; 
//const int mod = 1e9+7; 
const int M = 1e7+5;
int a[N],b[N],c,d,vis[N],pri[N],ans1[N],ans2[N],dp[N],p[N][4]; 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,k,ans,x,y,n0,n2,m0,m2,op,op1,op2;
string s;
map<pii,int>mp;
map<int,int>mmap;
//char mp[1005][1005];
//vector<int>v1[N],v2[N];
int lowbit(int x) {
	return x&-x;
}
char xx[N];
bool temp;
int kuai(int x,int y){
	int sum=1;
	x%=mod;
	while(y){
		if(y%2){
			y--;
			sum*=x;
			sum%=mod;
		  }
	  x*=x;
	  y/=2;
	  x%=mod;
	}
	return sum;
}
struct node{
	int shu;
	int id;
}jie[N];
bool cmp(node x,node y){
	return x.shu<y.shu;
}
void solve()
{
	cin>>n;
	F(i,1,n) cin>>a[i];
	int sum=0;
	dp[1]=0;//成功到达1;
	F(i,2,n+1){
		dp[i]=(100-a[i-1])*kuai(100,mod-2)%mod*sum%mod+1;
		dp[i]=dp[i]*100%mod*kuai(a[i-1],mod-2)%mod;
		sum+=dp[i]; sum%=mod;
	}
	ans=0;
	F(i,1,n+1) ans+=dp[i],ans%=mod;
	cout<<ans<<endl; 
}
signed main() 
{
	ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0); // cin.tie(nullptr);
    int T = 1;                                                                                                                                                                                                                                                                    
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    return 0;
}
/*
6 4 3 1 2
1 1 4 5 1 4
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值