Intercity Travelling CodeForces

编程入门 行业动态 更新时间:2024-10-18 01:30:28

<a href=https://www.elefans.com/category/jswz/34/1682963.html style=Intercity Travelling CodeForces"/>

Intercity Travelling CodeForces

大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1}$.

 

简单计数题, 枚举每种长度的贡献.

#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll;
const int P = 998244353, INF = 0x3f3f3f3f;const int N = 1e6+10;
int n,a[N],po2[N];int main() {scanf("%d", &n);REP(i,1,n) scanf("%d", a+i),(a[i]+=a[i-1])%=P;if (n==1) return printf("%d\n",a[n]),0;if (n==2) return printf("%d\n",2*a[1]+a[2]),0;po2[0] = 1;REP(i,1,n) po2[i] = po2[i-1]*2ll%P;int ans = a[n];REP(i,1,n-1) ans = (ans+((n-i-1ll)*po2[n-i-2]%P+2ll*po2[n-i-1])*a[i])%P;printf("%d\n", ans);
}

 

转载于:.html

更多推荐

Intercity Travelling CodeForces

本文发布于:2024-02-11 19:32:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1682951.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Intercity   Travelling   CodeForces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!