题意略。

思路:

比如现在n = 11。那么我们观察a[1.....n]的出现次数:

a[1]:2 ^ 10 + 10 * 2 ^ 9

a[2]:2 ^ 9 + 9 * 2 ^ 8

a[3]:2 ^ 8 + 8 * 2 ^ 7

.........

a[x]:2 ^ (n - x) + (n - x) * 2 ^ (n - x - 1)

凭借这个规律,我们可以通过快速幂求得答案。

详见代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = ;
const LL maxn = 1e6 + ; LL an[maxn]; LL qmod(LL a,LL n){
LL ret = ;
while(n){
if(n & ) ret = ret * a % mod;
n = n>>;
a = a * a % mod;
}
return ret;
} int main(){
int n;
scanf("%d",&n);
for(int i = ;i <= n;++i) scanf("%lld",&an[i]);
LL ans = ;
for(int i = ;i < n;++i){
LL temp1 = qmod(,n - i);
LL temp2 = LL(n - i) * qmod(,n - i - ) % mod;
ans += (temp1 + temp2) % mod * an[i] % mod;
}
ans += an[n];
ans %= mod;
printf("%lld\n",ans);
return ;
}

现在反过来想想,为什么可以这么去计算呢?

就是因为它要求的是所有情况的总和,这样我们才可以一个个把它们单独拿出来考虑。

Codeforces 1009E的更多相关文章

  1. Codeforces 1009E Intercity Travelling | 概率与期望

    题目链接 题目大意: 一个人要从$A$地前往$B$地,两地相距$N$千米,$A$地在第$0$千米处,$B$地在第$N$千米处. 从$A$地开始,每隔$1$千米都有$\dfrac{1}{2}$的概率拥有 ...

  2. CodeForces - 1009E Intercity Travelling

    题面在这里! 可以发现全是求和,直接拆开算贡献就好了 #include<bits/stdc++.h> #define ll long long using namespace std; c ...

  3. Intercity Travelling CodeForces - 1009E (组合计数)

    大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. FAIRR

    FAIRR 在进行一项工作时需要注意学习.应用和改进已有信息和成果,可参考FAIRR原则: Find existing info and result, Add to and Improve it, ...

  2. .net持续集成sonarqube篇之项目管理与用户管理

    系列目录 删除项目 在学习阶段,我们可能需要经常删除已构建的项目,在sonarqube中想要删除一个项目有两个入口,都在Administration导航栏内. 在项目内部的管理界面删除 如果项目处于打 ...

  3. static import和import的区别

    import static静态导入是JDK1.5中的新特性.一般我们导入一个类都用 import com.....ClassName;而静态导入是这样:import static com.....Cl ...

  4. TestNG使用@Parameter给要测试的方法传递参数

    当需要测试的方法含有参数时,可以通过@Parameters 注解给该方法传递参数. 比如下面这个类,要调用whoami则必须写一个main函数,然后在main函数中调用该函数,并传入参数,使用Test ...

  5. RobotFramework_4.SeleniumLibrary操作(二)

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  6. Linux平台 Oracle 19c RAC安装Part2:GI配置

    三.GI(Grid Infrastructure)安装 3.1 解压GI的安装包 3.2 安装配置Xmanager软件 3.3 共享存储LUN的赋权 3.4 使用Xmanager图形化界面配置GI 3 ...

  7. Could not launch "APP_NAME" process launch failed: 4294967295

    真机调试忽然遇到这个问题, Could not launch "APP_NAME" process launch failed: 如图所示: 模拟器上能正常调试………… 这个问题还 ...

  8. ios开发--给应用添加新的字体的方法

    1.网上搜索字体文件(后缀名为.ttf,或.odf) 2.把字体库导入到工程的resouce中 3.在程序添加以下代码 输出所有字体 NSArray *familyNames = [UIFont fa ...

  9. 自定义SWT控件六之自定义Tab

    6.自定义tab 本章节提供的自定义tab 分为两类 tab上带删除按钮和添加按钮,可删除tab和添加tab tab不可删除和添加 6.1 不可删除tab package com.view.contr ...

  10. javascript+jQuery补充

    一.jQuery事件绑定 <div class='c1'> <div> <div class='title'>菜单一</div> <div cla ...