题面

>CF传送门<

>洛谷传送门<

解法

显而易见,对于一个数\(a_i\),若果它出现在\(f\)序列中,必定\(a_i\)之前的元素要小于\(a_i\),我们设\(cnt_i\)为序列\(a\)中小于\(i\)的元素,

那么得到\(\sum_{i=1}^n a_i \times (\sum_{j=1}^{cnt_i+1} \frac{cnt_i!}{(j-1)!\times(cnt_i-j+1)!} \times (j - 1)! \times (n-j)!)\)

化简得\(\sum_{i=1}^n a_i \times (\sum_{j=1}^{cnt_i+1} \frac{cnt_i!}{(cnt_i-j+1)!} \times (n-j)!)\)

然后提出\(cnt_i!\)得\(\sum_{i=1}^n a_i \times cnt_i! \times ( \sum_{j=1}^{cnt_i+1} \frac{(n-j)!}{(cnt_i-j+1)!})\)

提取一个\((n-cnt_i-1)!\)得\(\sum_{i=1}^n a_i \times cnt_i! \times (n-cnt_i-1) \times ( \sum_{j=1}^{cnt_i+1} (^{n-j}_{n-cnt_i-1}))\)

又可得\(\sum_{i=1}^n a_i \times cnt_i! \times (n-cnt_i-1) \times (^n_{n-cnt_i})\)

所以答案为\(\sum_{i=1}^n \frac{a_i*n!}{n-l_i}\)

代码

#include <cstdio>
#include <algorithm>
#define ll long long
#define MOD 1000000007 using namespace std; ll jc[1000005], jcr[1000005];
ll a[1000005]; int main(){
int n; scanf("%d", &n);
for(ll i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
jc[0] = jcr[n + 1] = 1;
for(int i = 1; i <= n + 1; ++i)
jc[i] = (jc[i - 1] * i) % MOD;
for(int i = n; i >= 1; --i)
jcr[i] = (jcr[i + 1] * i) % MOD;
sort(a + 1, a + n + 1);
ll ans = 0; int cur_val = 0, cnt = 0;
for(int i = 1; a[i] != a[n]; ++i){
(a[i] == a[i - 1]) ? (++cnt) : (cur_val += cnt, cnt = 1);
ans += (((jc[n - cur_val - 1] * jcr[n - cur_val + 1]) % MOD) * a[i]) % MOD, ans %= MOD;
}
printf("%lld", ans); return 0;
}

[CF938E]Max History题解的更多相关文章

  1. 【计数】cf938E. Max History

    发现有一种奇怪的方法不能快速预处理? 复习一下常见的凑组合数的套路 You are given an array a of length n. We define fa the following w ...

  2. CodeForces 938E Max History 题解

    参考自:https://blog.csdn.net/dreaming__ldx/article/details/84976834 https://blog.csdn.net/acterminate/a ...

  3. Hdoj 1003.Max Sum 题解

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  4. Codeforces 938E Max History:排列 + 逆元【考虑单个元素的贡献】

    题目链接:http://codeforces.com/problemset/problem/938/E 题意: 定义f(a): 初始时f(a) = 0, M = 1. 枚举i = 2 to n,如果a ...

  5. luoguP3128 [USACO15DEC]最大流Max Flow 题解(树上差分)

    链接一下题目:luoguP3128 [USACO15DEC]最大流Max Flow(树上差分板子题) 如果没有学过树上差分,抠这里(其实很简单的,真的):树上差分总结 学了树上差分,这道题就极其显然了 ...

  6. 2018.12.12 codeforces 938E. Max History(组合数学)

    传送门 唉最开始居然把题给看错了. 其实是组合数学傻逼题呢. 题意简述:给出一个数列,定义一个与数列有关的fff函数,fff函数定义如下: 首先f=0,M=1f=0,M=1f=0,M=1,一直重复如下 ...

  7. Max History CodeForces - 938E (组合计数)

    You are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for e ...

  8. CF1083C Max Mex 线段树

    题面 CF1083C Max Mex 题解 首先我们考虑,如果一个数x是某条路径上的mex,那么这个数要满足什么条件? 1 ~ x - 1的数都必须出现过. x必须没出现过. 现在我们要最大化x,那么 ...

  9. Educational Codeforces Round 38 部分题解

    D. Buy a Ticket 分析 建一个源点,连向所有结点,边的花费为那个结点的花费,图中原有的边花费翻倍,最后跑一遍最短路即可. code #include<bits/stdc++.h&g ...

随机推荐

  1. C++ Primer笔记(1)——连续读取数据、类型对应的尺寸、类型转换、字符串分行写法

    这次要看看C++ Primer,这本基本上就是必读书籍了.下面的内容就是一些之前没有学过的知识的笔记. 读取数量不定的输入数据 虽然很简单,但是还是记一下: #include <iostream ...

  2. lnmp一键安装包卸载mysql,重新安装报错mysql57-community-release conflicts with mysql-community-release-el6-5.noarch

    环境:CentOS Linux release 7.6.1810 lnmp1.5 独立下载mysql仓库 wget -i -c http://dev.mysql.com/get/mysql57-com ...

  3. 【Qt开发】V4L2 API详解 背景知识 打开设备设置参数

    www.linuxtv.org下,有篇文档详细讲解了V4L2相关知识和体系结构.是V4L2方面最全面的文档.可以通过它学习V4L2的一些思路和想法. http://www.linuxtv.org/do ...

  4. vue仿阿里云后台管理(附加阿里巴巴图标使用)

    先看下页面截图,在线演示地址http://aliadmin.zengjielin.top 下面有开源的代码 页面分成三大部分头部,头部菜单栏,侧边菜单栏,右侧内容栏. 现在我们担心的是怎么使用侧边栏. ...

  5. Canvas入门04-绘制矩形

    使用的API: ctx.strokeRect(x, y, width, height) 给一个矩形描边 ctx.fillRect(x, y, width, height) 填充一个矩形 ctx.cle ...

  6. django 的 MTV 流程图

  7. 磁盘管理|df、du|分区 fdisk |格式化

    3.磁盘管理 3.1命令df ·用于查看已挂载磁盘的总容量,使用容量,剩余容量等. -i:查看inodes的使用情况 -h:使用合适的单位显示 -k:以KB为单位显示 -m:以MB为单位显示 3.1. ...

  8. 自动构建War包的Ant build.xml模板

    <?xml version="1.0" encoding="UTF-8" ?> <project name="[*****]你的项目 ...

  9. Dp test solution

    Dp test solution 按照难易程度排序题解: Problem B Problem Description Tarzan 现在想要知道,区间 [L,R] 内有多少数是优美的.我们定义一个数是 ...

  10. exosip2 build

    Build eXosip on Win 1. download exosip  http://savannah.nongnu.org/projects/exosip/ 2. download libc ...