[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) 直 ...
随机推荐
- 《SQL与数据库基础》17. InnoDB引擎
目录 InnoDB引擎 逻辑存储结构 架构 内存结构 磁盘结构 后台线程 事务原理 事务基础 redo log undo log MVCC 基本概念 隐式字段 undo log版本链 readView ...
- 我们能从PEP 703中学到什么
PEP703是未来去除GIL的计划,当然现在提案还在继续修改,但大致方向确定了. 对于实现细节我没啥兴趣多说,挑几个我比较在意的点讲讲. 尽量少依赖原子操作的引用计数 没了GIL之后会出现两个以上的线 ...
- [SDR] SDR 教程实战 —— 利用 GNU Radio + HackRF 手把手深入了解蓝牙协议栈(从电磁波 -> 01数据流 -> 蓝牙数据包)
目录 0.前言 1.体验 2.代码解析 2.1 目录结构 2.2 main.py 2.3 grc gnu radio 流程图 2.4 如何从 01 数据流中解析出 BLE 广播包 2.4.1 物理层 ...
- 《Docker到Kubernetes容器运维实战》简介
#好书推荐##好书奇遇季#<Docker到Kubernetes容器运维实战>已经出版.本书帮助读者系统掌握Docker与K8s运维技能. 本书内容 本书分两部分系统介绍Docker与K ...
- 如何理解DDD中的值对象
引言 实体和值对象是领域驱动设计中的两个重要概念.相对实体而言,值对象更加抽象,理解起来也更晦涩一些.那么该如何理解值对象?我们先来看一下<实现领域驱动设计>书中对值对象的定义: 值对象 ...
- Python 潮流周刊第 20 期(摘要)
你好,我是猫哥.本周刊分享优质的 Python.AI 及通用技术内容,大部分为英文.这里是标题摘要版,查看全文请至☞:https://pythoncat.top/posts/2023-09-16-we ...
- 小札 Combinatorics 2
对于 Newton Expansion,式子本身的证明其实无甚可翻新的花样,但是题还是很有意思的.比如 codeforces - 1332E Height All the Same 这个. 首先给出几 ...
- JUC并发编程(3)—锁中断机制
目录 1.什么是中断 2.源码解读(中断的相关API) 3.如何使用中断标识停止线程 学习视频:https://www.bilibili.com/video/BV1ar4y1x727 1.什么是中断 ...
- FX3U-3A-ADP模拟量和数字量之间转换
简单的例子: 0-10V对应0-8,4-20mA对应0-30 以下是对上面例子的详解: 电压: 电压(0-10V) 0-10V对应着数字量0-4000 数字量与变频器HZ量之间的关系是(4000-0) ...
- NFC and Contactless Technologies
NFC and Contactless Technologies NFC与无接触技术 NFC technology enables simple and safe two-way interactio ...