Intercity Travelling CodeForces - 1009E (组合计数)
大意: 有一段$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 (组合计数)的更多相关文章
- Codeforces D. Intercity Travelling(区间组合)
题目描述: D. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes in ...
- Yet Another Problem On a Subsequence CodeForces - 1000D (组合计数)
大意:定义一个长为$k>1$且首项为$k-1$的区间为好区间. 定义一个能划分为若干个好区间的序列为好序列. 给定序列$a$, 求有多少个子序列为好序列. 刚开始一直没想出来怎么避免重复计数, ...
- Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)
大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...
- Different Subsets For All Tuples CodeForces - 660E (组合计数)
大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...
- Singer House CodeForces - 830D (组合计数,dp)
大意: 一个$k$层完全二叉树, 每个节点向它祖先连边, 就得到一个$k$房子, 求$k$房子的所有简单路径数. $DP$好题. 首先设$dp_{i,j}$表示$i$房子, 分出$j$条简单路径的方案 ...
- GukiZ and Binary Operations CodeForces - 551D (组合计数)
大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足 的序列. 刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$ ...
- 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 ...
- Codeforces 1009 E. Intercity Travelling(计数)
1009 E. Intercity Travelling 题意:一段路n个点,走i千米有对应的a[i]疲劳值.但是可以选择在除终点外的其余n-1个点休息,则下一个点开始,疲劳值从a[1]开始累加.休息 ...
- bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)
黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...
随机推荐
- spring boot 之 如何创建spring boot项目
创建spring boot的方式有非常多,今天我们使用maven来进行创建spring boot项目,因为maven使用的非常广泛,也很好用,很多IDE也都支持maven. 1 创建maven项目 1 ...
- .NET开发人员的完美.gitignore文件
# Build and Object Folders bin/ obj/ # Nuget packages directory packages/ ## Ignore Visual Studio te ...
- golang通过ssh实现远程文件传输
使用ssh远程操作文件, 主要是创建ssh, 直接上代码 import ( "fmt" "github.com/pkg/sftp" "golang.o ...
- arcgis python 异常处理和信息处理
#coding=utf8 import arcpy import os import sys import ylpy try: a=1111111 b=0000 c=a/b except Except ...
- Win10系统安装VMware-viclient-6.0无响应问题解决方法
背景:笔记本重做系统升级至Win10系统后,由于工作需要,得安装VMware-viclient-6.0软件进行远程连接. 问题:没有出现网上那种各种报错情况,只是在点击“安装”按钮的时候没弹出任何等待 ...
- BitmapFactory之Options
package com.loaderman.customviewdemo; import android.app.Activity; import android.graphics.Bitmap; i ...
- MauiMETA工具的使用(一)
MauiMETA工具的使用(一) 摘自:https://www.jianshu.com/p/a377119947f8 tianxiaoMCU 关注 2018.12.21 14:15 字数 267 ...
- 123456---com.twoapp.xiaoxiaozuqiujiang---小小足球将
com.twoapp.xiaoxiaozuqiujiang---小小足球将
- java8中计算两个日期时间LocalDateTime的时间差,格式化成xx年yy月zz日aa时bb分cc秒
原则上应该适用Period来计算,因为他是专门为这种需求设计的.当时他只能计算到两个时间差的,年月日 传入参数Period.between(LocalDate,LocalDate) 这里是计算两个Lo ...
- maven项目创建.m2文件夹
创建为.m2.,m2前后都要有点,然后去掉后面的点 settings.xml文件如下: <?xml version="1.0" encoding="UTF-8&qu ...