[ABC263E] Sugoroku 3
Problem Statement
There are $N$ squares called Square $1$ though Square $N$. You start on Square $1$.
Each of the squares from Square $1$ through Square $N-1$ has a die on it. The die on Square $i$ is labeled with the integers from $0$ through $A_i$, each occurring with equal probability. (Die rolls are independent of each other.)
Until you reach Square $N$, you will repeat rolling a die on the square you are on. Here, if the die on Square $x$ rolls the integer $y$, you go to Square $x+y$.
Find the expected value, modulo $998244353$, of the number of times you roll a die.
Notes
It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, there is a unique integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.
Constraints
- $2 \le N \le 2 \times 10^5$
- $1 \le A_i \le N-i(1 \le i \le N-1)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$
$A_1$ $A_2$ $\dots$ $A_{N-1}$
Output
Print the answer.
Sample Input 1
3
1 1
Sample Output 1
4
The sought expected value is $4$, so $4$ should be printed.
Here is one possible scenario until reaching Square $N$:
- Roll $1$ on Square $1$, and go to Square $2$.
- Roll $0$ on Square $2$, and stay there.
- Roll $1$ on Square $2$, and go to Square $3$.
This scenario occurs with probability $\frac{1}{8}$.
Sample Input 2
5
3 1 2 1
发现正着定义状态很难定义。定义 \(dp_i\) 表示从第 \(i\) 个点到达第 \(n\) 个点的期望步数。
那么可以列出 $$dp_i=\frac{1}{a_i+1} dp_i+\frac{1}{a_i+1} dp_{i+1}\cdots+\frac{1}{a_i+1} dp_{i+a_i}+1$$
\]
\]
对dp数组维护后缀和即可。
#include<cstdio>
const int N=2e5+5,P=998244353;
int dp[N],a[N],n,add;
long long s[N],ret;
int pow(int x,int y)
{
if(!y)
return 1;
int t=pow(x,y>>1);
return y&1? 1LL*t*t%P*x%P:1LL*t*t%P;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<n;i++)
scanf("%d",a+i);
for(int i=n-1;i>=1;i--)
{
// scanf("%d",a+i);
dp[i]=1LL*(s[i+1]-s[i+a[i]+1]+P)%P*pow(a[i],P-2)%P+1LL*(a[i]+1)*pow(a[i],P-2)%P ;
dp[i]%=P;
// printf("%",dp[i]);
s[i]=s[i+1]+dp[i];
s[i]%=P;
}
printf("%d",dp[1]);
}
[ABC263E] Sugoroku 3的更多相关文章
- SFC游戏列表(维基百科)
SFC游戏列表 日文名 中文译名 英文版名 发行日期 发行商 スーパーマリオワールド 超级马里奥世界 Super Mario World 1990年11月21日 任天堂 エフゼロ F-Zero F-Z ...
- ARC145~152 题解
比赛标号从大到小排列 . 因为博主比较菜所以没有题解的题都是博主不会做的 /youl ARC144 以前的比赛懒得写了 . 目录 AtCoder Regular Contest 152 B. Pass ...
- ARC149(A~E)
Tasks - AtCoder Regular Contest 149 又是114514年前做的题,现在来写 屯了好多,清一下库存 A - Repdigit Number (atcoder.jp) 直 ...
随机推荐
- 一行命令即可启动 Walrus丨入门教程
应用管理平台 Walrus 已正式开源,本文将介绍如何上手安装 Walrus 以及如何借助 Walrus 进行应用部署. 开源地址:https://github.com/seal-io/walrus ...
- docker搭建CMS靶场
项目地址:https://github.com/Betsy0/CMSVulSource 该项目是为了方便在对CMS漏洞进行复现的时候花费大量的时间在网上搜索漏洞源码,从而有了此项目.此项目仅为安全研究 ...
- 【matplotlib基础】--文本标注
Matplotlib 文本和标注可以为数据和图形之间提供额外的信息,帮助观察者更好地理解数据和图形的含义. 文本用于在图形中添加注释或提供更详细的信息,以帮助观察者理解图形的含义.标注则是一种更加细粒 ...
- 2.14 PE结构:地址之间的转换
在可执行文件PE文件结构中,通常我们需要用到地址转换相关知识,PE文件针对地址的规范有三种,其中就包括了VA,RVA,FOA三种,这三种该地址之间的灵活转换也是非常有用的,本节将介绍这些地址范围如何通 ...
- 钉钉旧版服务端SDK支持异步方法的升级改造
最近项目中需要对接钉钉,有些钉钉 API 的访问需要使用旧版服务端 SDK 才能搞定,但是这个 SDK 使用的还是 .NET Framework 2.0 框架,不能跨平台部署,也不支持 async\a ...
- Note -「网络流 flows」
基本没有严谨证明. Part. 1 概念 Part. 1-1 流网络 流网络是一个有向图(不考虑反向边),我们把这个图记为 \(G=(V,E)\). 其中有两个特殊的点 \(s,t\),分别成为源点和 ...
- 好用!这些工具国庆一定要研究下「GitHub 热点速览」
再过 3 天就要开始一年最长的假期--国庆长假了,这次除了宅家.出游之外,多了一个新选项:研究下哪些项目可以安排上,来辅助自己的日常开发. 你觉得一周获得 4k star 的 hyperdx 如何,它 ...
- IP协议的发展历程
1. IP协议 1.1为什么需要IP协议 好像ip地址就像每个人的家门号一样家喻户晓,被大家默认用来作为寻址的门牌号,起初,设计IP地址也是为了寻找某台主机,但是作为世界上家喻户晓的IPv4,大家不应 ...
- win如何根据端口号查找并杀死一个线程
查看端口占用 netstat -ano | findstr "端口号" 杀死一个进程 taskkill /pid 进程号 -f
- destoon根据目录下的html文件生成地图索引
因为项目需要,destoon根据目录下的html文件生成地图索引,操作方法,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...