Educational Codeforces Round 47 - E. Intercity Travelling

题目

题意:

司机不休息的话,走1公里,消耗a1,再走一公里消耗a2,然后a3、a4。这样消耗下去。

有休息站,可以让a数组重新数。

问你总消耗的期望*2^(n-1)。

POINT:

可以推一下。px为x这个坐标的期望组成。

p1=1*a1 (第一个永远是a1)

p2=1/2*a1+1/2*a2 (2这个点,有1/2的概率有休息站,那么1/2*a1,有1/2没有,那么从上一个点p1增加过来:

扫描二维码关注公众号,回复: 2328228 查看本文章

1/2*p1且下标都增加1)

p3=1/2*a1+1/4*a2+1/4*a3

可知p(y)可以从p(y-1)算出来。

答案为p1加到pn。 

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

#define  LL long long

const LL mod = 998244353;
const LL maxn = 1e6+66;
LL b[maxn];
LL a[maxn];
int main()
{
	LL n;
	scanf("%lld",&n);
	b[0]=1;
	for(LL i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		b[i]=b[i-1]*2%mod;
	}
	LL pre=b[n-1]*a[1]%mod;
	LL ans=0;
	ans+=pre;
	for(LL i=2;i<=n;i++){
		pre=pre+mod-b[n-i+1]*a[i-1]%mod+b[n-i]*a[i]%mod+b[n-i]*a[i-1]%mod;
		pre%=mod;
		(ans+=pre)%=mod;
	}
	printf("%lld\n",ans);



}

猜你喜欢

转载自blog.csdn.net/mr_treeeee/article/details/81070958
今日推荐