[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) 直 ...
随机推荐
- 浅谈API安全的应用
理论基础 API它的全称是Application Programming Interface,也叫做应用程序接口,它定义了软件之间的数据交互方式.功能类型.随着互联网的普及和发展,API 从早期的 ...
- 掌握Go的运行时:从编译到执行
讲解Go语言从编译到执行全周期流程,每一部分都会包含丰富的技术细节和实际的代码示例,帮助大家理解. 关注微信公众号[TechLeadCloud],分享互联网架构.云服务技术的全维度知识.作者拥有10+ ...
- Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档
Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档, 还支持 xlsx 和 docx 文件的加密(具体使用看文档) ...
- 微信小程序 setData accepts an Object rather than some undefined 解决办法
问题 setData accepts an Object rather than some undefined setData接受一个对象而不是一些定义 让我猜猜, 你一定是在加载index页面(首页 ...
- Solution -「BZOJ 3779」重组病毒
Description Link. Given is a tree. Every node initially has a color which is different from others'. ...
- Solution -「洛谷 P7395」「CoE-I 2021C」弹珠游戏
Description Link. 游戏在 \(4\times4\) 的菱形棋盘上进行: 两名玩家轮流放置弹珠,可以在横向.纵向.\(45\) 度斜线.\(135\) 度斜线方向未放置弹珠的位置连续放 ...
- java开发面试笔记
目录 1.hashMap hashmap源码分析-逐行注释版: 2.线程池 3.MySQL数据库引擎.事务.锁机制 1. 引擎 2. 事务 索引 3. 锁: 4. 调优问题怎么回答? 4.SQL语句 ...
- ElasticSearch系列——查询、Python使用、Django/Flask集成、集群搭建,数据分片、位置坐标实现附近的人搜索
@ 目录 Elasticsearch之-查询 一 基本查询 1.1 match查询 1.2 term查询 1.3 terms查询 1.4 控制查询的返回数量(分页) 1.5 match_all 查询 ...
- Xshell链接不上解决问题
#5.远程连接工具排错? #一.测试网络是否通畅 1.测试网络连通性:ping 服务端ip地址 2.关闭防火墙 systemctl stop firewalld #关闭防火墙 systemctl di ...
- 计算机的数值转化与网络的IP地址分类与地址划分
数值转换 数字系统由来 远古时代是没有数字系统非位置化数字系统: 罗马数字 (I-1.II-2.III-3.IV-4.V-5.VI-6.VII-7.VIII-8.IX-9.X-10) 位置话数字化系统 ...