Codeforces ~ 1009E ~ Intercity Travelling (数学期望 + 规律)

题意

你要从0~n,有n个站点(1~n),每个站点都有1/2的几率有休息点。你连续坐k站时,每两站间的疲劳值为a1,a2……ak,如果第k站有休息点,那么你可以在此处休息,然后接下来的站点的疲劳值又从a1开始。求p(疲劳值的期望)*2^(n-1)。


思路

写出前几项的概率,可以发现规律,然后按照规律去写就好了。


图片来自下面博客

参考博客:Educational Codeforces Round 47 (Rated for Div. 2) 题解

#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
typedef long long LL;
int n;
LL a, c, ans;
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        c = (2*c+a)%MOD;
        scanf("%lld", &a);
        ans = (2*ans+c+a)%MOD;
    }
    printf("%lld\n", ans);
    return 0;
}
/*
2
1 2
*/



猜你喜欢

转载自blog.csdn.net/zscdst/article/details/81058947
今日推荐