大意: 有一段$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);
}

Intercity Travelling CodeForces - 1009E (组合计数)的更多相关文章

  1. Codeforces D. Intercity Travelling(区间组合)

    题目描述: D. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes in ...

  2. Yet Another Problem On a Subsequence CodeForces - 1000D (组合计数)

    大意:定义一个长为$k>1$且首项为$k-1$的区间为好区间. 定义一个能划分为若干个好区间的序列为好序列. 给定序列$a$, 求有多少个子序列为好序列. 刚开始一直没想出来怎么避免重复计数, ...

  3. Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)

    大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...

  4. Different Subsets For All Tuples CodeForces - 660E (组合计数)

    大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...

  5. Singer House CodeForces - 830D (组合计数,dp)

    大意: 一个$k$层完全二叉树, 每个节点向它祖先连边, 就得到一个$k$房子, 求$k$房子的所有简单路径数. $DP$好题. 首先设$dp_{i,j}$表示$i$房子, 分出$j$条简单路径的方案 ...

  6. GukiZ and Binary Operations CodeForces - 551D (组合计数)

    大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足 的序列. 刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$ ...

  7. Max History CodeForces - 938E (组合计数)

    You are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for e ...

  8. Codeforces 1009 E. Intercity Travelling(计数)

    1009 E. Intercity Travelling 题意:一段路n个点,走i千米有对应的a[i]疲劳值.但是可以选择在除终点外的其余n-1个点休息,则下一个点开始,疲劳值从a[1]开始累加.休息 ...

  9. bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)

    黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...

随机推荐

  1. Publish site through visual studio

    https://www.c-sharpcorner.com/UploadFile/4b0136/getting-started-with-iis-host-and-publish-in-mvc-5/ ...

  2. perl 语法速查 | 模块安装

    perl -MCPAN -e shell install Bio::SeqIO 或者直接perl -MCPAN -e 'install Excel::Writer::XLSX' 用cpan装不上,编译 ...

  3. java模拟post进行文件提交 采用httpClient方法

    package com.jd.vd.manage.util.filemultipart; import java.io.BufferedReader;import java.io.File;impor ...

  4. i18n 语言码和对应的语言库

    语言码 语言名称 af Afrikaans am Amharic ar Arabic az Azerbaijani be Belarusian bg Bulgarian bh Bihari bn Be ...

  5. pytorch常用损失函数

    损失函数的基本用法: criterion = LossCriterion() #构造函数有自己的参数 loss = criterion(x, y) #调用标准时也有参数 得到的loss结果已经对min ...

  6. Qt kdChart 甘特图案例

    KDChart  甘特图在Qt中的加载使用案例,代码来自官方 mainwindow.h /******************************************************* ...

  7. Canal——Canal-Adapter源码在IDEA部署运行

    一.下载源码 下载地址:https://github.com/alibaba/canal 我这里用的是canal-1.1.4版本 源码结构 client-adapter项目就是本次要部署运行的 源码导 ...

  8. Mysql安装、查看密码、修改密码、初始化、修改字符类型

    安装mysql 参照python篇一键安装lnmp.安装完之后再按照下面修改密码,修改配置文件,否则安装的时候就修改配置文件会出错. 注意:这也是二进制安装mysql.另一种二进制安装容易出错,生产环 ...

  9. 【Leetcode_easy】830. Positions of Large Groups

    problem 830. Positions of Large Groups solution1: class Solution { public: vector<vector<int&g ...

  10. 理解ADFS相关概念

    核心概念 Claims是?Token是?Security Token是?Security Token Server (STS)是? 声明与令牌无关,但通过封装在安全令牌中来进行网络传输! SSL证书是 ...