当前位置:网站首页>E - Sugoroku 3(期望dp)
E - Sugoroku 3(期望dp)
2022-08-09 23:16:00 【Harris-H】
E - Sugoroku 3(期望dp)
d p i = ∑ j = i i + a i d p j a i + 1 + 1 dp_i=\dfrac{\sum_{j=i}^{i+a_i}dp_j}{a_i+1}+1 dpi=ai+1∑j=ii+aidpj+1
右边的 d p i dp_i dpi 移项得到:
a i a i + 1 d p i = ∑ j = i + 1 i + a i d p j a i + 1 + 1 \dfrac{a_i}{a_{i}+1}dp_i=\dfrac{\sum_{j=i+1}^{i+a_i}dp_j}{a_i+1}+1 ai+1aidpi=ai+1∑j=i+1i+aidpj+1
d p i = ∑ j = i + 1 i + a i d p j a i + a i + 1 a i = ( ∑ j = i + 1 i + a i d p j ) + a i + 1 a i dp_i=\dfrac{\sum_{j=i+1}^{i+a_i}dp_j}{a_i}+\dfrac{a_i+1}{a_i}=\dfrac{(\sum_{j=i+1}^{i+a_i}dp_j)+a_i+1}{a_i} dpi=ai∑j=i+1i+aidpj+aiai+1=ai(∑j=i+1i+aidpj)+ai+1
取模用逆元递推即可。
时间复杂度: O ( n ) O(n) O(n)
// Problem: E - Sugoroku 3
// Contest: AtCoder - LINE Verda Programming Contest(AtCoder Beginner Contest 263)
// URL: https://atcoder.jp/contests/abc263/tasks/abc263_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Date: 2022-08-09 12:44:54
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=998244353;
const int hashmod[4] = {
402653189,805306457,1610612741,998244353};
#define mst(a,b) memset(a,b,sizeof a)
#define db double
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y){
if(x<y) x=y;
}
template <typename T>
void cmn(T &x,T y){
if(x>y) x=y;
}
int n;
ll dp[N];
ll suf[N];
ll a[N];
ll inv[N];
ll p=mod;
void init(int n){
inv[1]=1;
for(int i=2;i<=n;i++)
inv[i]=(p-p/i)*inv[p%i]%p;
}
int main(){
ll q = 1;
cin>>n;
rep(i,1,n-1) cin>>a[i];
init(n);
dp[n] = 0;
for(int i=n-1;i;i--){
dp[i] = (suf[i+1]-suf[i+a[i]+1]+a[i]+1)*inv[a[i]]%mod;
suf[i] = (suf[i+1] + dp[i])%mod;
}
printf("%lld",(dp[1]%mod+mod)%mod);
return 0;
}
边栏推荐
- What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
- 博弈小游戏
- 多商户商城系统功能拆解25讲-平台端分销申请
- Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
- Digital wallets, red sea ecological rapid introduction of small programs can help capture device entry wisdom
- 什么是平面文件数据库? 如何导入多种格式的文件:DSV、JSON、XML?
- Seq2Seq论文阅读笔记
- AirFlow介绍
- redis分布式锁代码示例
- IT传奇人物菲尔德的转型经验教训及给CIO的建议
猜你喜欢
随机推荐
YOLOV5学习笔记(七)——训练自己数据集
微信小程序获取微信用户步数
conda新建环境时报错NotWritableError: The current user does not have write permissions
领跑政务云,连续五年中国第一
服务发现@EnableDiscoveryClient
网络协议05 -网络层
RebatMq消息中间件(一) 各个中间件介绍
Cmake 用法记录
【数据存储】signed,unsigned到底怎么区分?如何计算?
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
YOLOV5 study notes (7) - training your own data set
Qt 之 QDateEdit 和 QTimeEdit
mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
ECCV 2022 | 微软开源TinyViT :搞定小模型的预训练能力
Eureka protects itself
下班后用微信处理工作时发病身亡,法院判决:工伤!
HStreamDB v0.9 发布:分区模型扩展,支持与外部系统集成
ES6 从入门到精通 # 12:数组的扩展方法一
FreeRTOS任务基础
How to match garbled characters regularly?








