[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) 直 ...
随机推荐
- Doris 再次启动FE失败的思考
Doris再次启动FE失败的思考 背景描述 在昨天已经成功下载安装最新稳定版docker.拉取doris-0.15.0版本的镜像.将镜像挂载道本地Doris源码目录.完成了doris的编译之后,今天在 ...
- 手把手教你使用Vite构建第一个Vue3项目
写在前面 在之前的文章中写过"如何创建第一个vue项目",但那篇文章写的是创建vue2的 项目. 传送门如何创建第一个vue项目 打开Vue.js官网:https://cn.vue ...
- 本地项目上传到Git仓库
1. 进入项目主目录,打开Git Bash,执行以下命令,将项目变为一个git管理的项目: $ git init 执行成功后,会在项目根目录生成一个.git的文件夹. 可以执行以下命令查看项目状态: ...
- KRPano插件解密大师更新支持最新版KRPano的XML/JS解密
KRPano插件解密大师是一款专业的全景解密工具,它可以帮助你轻松解密KRPano的XML/JS插件,还能分析下载静态和动态网站的资源.你无需任何编程知识,只需一键点击,就能快速完成解密,学习全景开发 ...
- KRPANO资源分析工具下载四方环视全景图
提示:目前分析工具中的全景图下载功能将被极速全景图下载大师替代,相比分析工具,极速全景图下载大师支持更多的网站(包括各类KRPano全景网站,和百度街景) 详细可以查看如下的链接: 极速全景图下载大师 ...
- SpringBoot使用@Async注解8大坑点
前言 SpringBoot中,@Async注解可以实现异步线程调用,用法简单,体验舒适. 但是你一定碰到过异步调用不生效的情况,今天,我就列出90%的人都可能会遇到的8大坑点. 正文 1.未启用异步支 ...
- 位图(bitmap)原理以及实现
大家好,我是蓝胖子,我一直相信编程是一门实践性的技术,其中算法也不例外,初学者可能往往对它可望而不可及,觉得很难,学了又忘,忘其实是由于没有真正搞懂算法的应用场景,所以我准备出一个系列,囊括我们在日常 ...
- 【FAQ】关于获取运动健康数据的常见问题及解答
目录 一.Health Kit健康数据采样, 原子采样数据问题 二.Health Kit查询历史数据查询数据和返回数据不一致 三.Health Kit关于获取历史数据问题 四.调用Health Kit ...
- vue 基于原生动画的自动滚动表格
前言 公司展示大屏需要写滚动表格,通过滚动播放数据,自己随便摸了一个基于动画的自动滚动表格 原理 根据每行的大小和设置的每行滚动时间设置滚动位置,动态添加动画,并把数组第一项移动到最后一项,并订阅该动 ...
- Apache协议原文及中文翻译
Apache协议原文及中文翻译 参考链接 原文 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TER ...