题目链接:http://codeforces.com/contest/1009/problem/E
解题心得:
- 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是看了大佬博客才知道的规律。这个题要预先处理2的n次方,不然快速幂也会TLE。
- 推荐两个大佬的博客:
- https://blog.csdn.net/u010746456/article/details/81057082
- https://blog.csdn.net/hyp1231/article/details/81061186
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6+100; const long long MOD = 998244353; typedef long long ll; ll num[maxn], pow2[maxn]; ll n; void get_pow2(){ pow2[0] = 1; for(int i=1;i<=n;i++) pow2[i] = (pow2[i-1] * 2) % MOD; } void init() { scanf("%lld",&n); for(ll i=1;i<=n;i++) { scanf("%lld",&num[i]); } get_pow2(); } void solve(){ ll ans = 0; for(ll i=1;i<=n;i++){ ll temp; if(i == n) temp = 1; else temp = pow2[n-i] + pow2[n-i-1]*(n-i); temp %= MOD; ans += temp*num[i]; ans %= MOD; } printf("%lld\n",ans); } int main() { init(); solve(); return 0; }
原文地址:https://www.cnblogs.com/GoldenFingers/p/9358719.html
时间: 2024-11-07 20:31:24