AtCoder Grand Contest 028 B - Removing Blocks 解题报告
B - Removing Blocks
Time limit : 2sec / Memory limit : 1024MB
Score : 600 points
Problem Statement
There are \(N\) blocks arranged in a row, numbered 1 to \(N\) from left to right. Each block has a weight, and the weight of Block \(i\) is \(A_i\). Snuke will perform the following operation on these blocks \(N\) times:
Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself).
Here, two blocks \(x\) and \(y\) ( \(x≤y\) ) are \(connected\) when, for all \(z\) ( \(x≤z≤y\) ), Block \(z\) is still not removed.
There are \(N\)! possible orders in which Snuke removes the blocks. For all of those \(N\)! orders, find the total cost of the \(N\) operations, and calculate the sum of those \(N\)! total costs. As the answer can be extremely large, compute the sum modulo \(10^9+7\).
Constraints
\(1≤N≤10^5\)
\(1≤A_i≤10^9\)
All values in input are integers.
题意:给你\(n\)个位置,每个位置有权值\(a\),随机删去位置上的数,得到的权值是这个位置相连的联通块内的权值和(联通的定义是位置相邻且数没有删去),每次删完,求所有删数方案的权值和。
发现权值和就是一次删数(指删完整个序列)的权值期望乘上删数方案\(n!\),于是我们需要求删数的权值期望。
考虑每个位置的贡献,当位置\(i\)被删去时,\(\tt{ta}\)的连通性一共有\(n\)种可能。
设删去时的连通块为\((i,j)\),则在这种情况下删\(\tt{ta}\)的可能性是\(P_{i,j}=\frac{1}{|i-j|+1}\)
则\(i\)的整个权值贡献为\(a_i\sum_{j=1}^nP_{i,j}\)
则答案为
\]
发现\(p\)可以预处理前缀和,枚举一下\(i\)就可以了
Code:
#include <cstdio>
#define ll long long
const int N=1e5+10;
const ll mod=1e9+7;
int n;
ll a[N],fac=1,inv[N],ans;
ll quickpow(ll d,ll k)
{
ll f=1;
while(k)
{
if(k&1) f=f*d%mod;
d=d*d%mod;
k>>=1;
}
return f;
}
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
int main()
{
scanf("%d",&n);
rep(i,1,n) fac=fac*i%mod,inv[i]=quickpow(i,mod-2),scanf("%lld",a+i);
rep(i,1,n) (inv[i]+=inv[i-1])%=mod;
rep(i,1,n) (ans+=a[i]*(inv[i]+inv[n-i+1]-1))%=mod;
printf("%lld\n",ans*fac%mod);
return 0;
}
2018.10.24
AtCoder Grand Contest 028 B - Removing Blocks 解题报告的更多相关文章
- [AtCoder]Grand Contest 028
A Two Abbreviations 题意:给定两个串,长度为\(N\)的\(A\)和长度为\(M\)的\(B\),一个串\(S\)被称为好的,当且仅当:这个串的长度\(L\)能被\(N,M\)整除 ...
- AtCoder Grand Contest 028 A:Two Abbreviations
题目传送门:https://agc028.contest.atcoder.jp/tasks/agc028_a 题目翻译 给你两个串\(s\)与\(t\),长度分别为\(n,m\).问你存不存在一个串长 ...
- AtCoder Grand Contest 019 F-yes or no
AtCoder Grand Contest 019 F-yes or no 解题思路: 考虑一个贪心策略,假设当前还有 \(x\) 道 \(\text{yes}\) 和 \(y\) 道 \(\text ...
- Atcoder Grand Contest 036 D - Negative Cycle
Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
随机推荐
- Angular简单总结
AngularJS AngularJS四大特征 MVC模式 双向绑定 依赖注入 模块化设计 AngularJS 表达式 AngularJS 表达式写在双大括号内{{expression }},可以包含 ...
- C#在textBox中输出一个数组
//将数组输出到文本框测试 for(i=0;i<arr.Length-1;i++){ this.textBox1.Text=this.textBox1.Text+arr[i]; }
- MySQL的边角料
//1查询对应数据库所有的表 SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA ="数据库名" 2 查询数据 ...
- 糖果 南阳acm589
糖果 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 topcoder工作室的PIAOYIi超级爱吃糖果,现在他拥有一大堆不同种类的糖果,他准备一口气把它们吃完,可是 ...
- SIMD数据并行(一)——向量体系结构
在计算机体系中,数据并行有两种实现路径:MIMD(Multiple Instruction Multiple Data,多指令流多数据流)和SIMD(Single Instruction Multip ...
- 小米Pro 15.6 系统重装记录
参考链接:http://bbs.xiaomi.cn/t-14321262,主要是miui论坛和小米社区的一位同学的教程,. 这位同学是针对12.5和13.3的版本做的教程,15.6和之前的版本有一小点 ...
- oracle查询优化,存储过程select表循环插入另一个表,以及索引重建
查询语句pl/sql中用F5优化语句 ORACLE的explain plan工具的作用只有一个,获取语句的执行计划1.语句本身并不执行,ORACLE根据优化器产生理论上的执行计划2.语句的分析结果存放 ...
- SQL Server中2008及以上 ldf 文件过大的解决方法
在SQL Server中经常遇到事务日志变大的情况,除了将数据库设置为“自动收缩”外,还可以使用下面的SQL命令进行快速清除数据库中的事务日志,命令如下: - 第一步:清空日志 ALTER DAT ...
- Delphi中ModalResult的使用
Delphi中ModalResult的功能非常实用. 在自己设计的Dialog界面中,选择相应的按钮,设置按钮的 ModalResult属性为mrOK .mrCancel 等.这样的设置,当按下该按钮 ...
- mysql 函数以及操作总结
1. 拼接 concat(参数1,参数2,.. ,参数) 实现将多个字符串拼接到一起 要批量修改一个字段值 字段值又是复杂的sql 计算得来 通过查询字段值 和 修改的条件fundId(这是 ...