You are given an array a of length n. We define fa the following way:

  • Initially fa = 0, M = 1;
  • for every 2 ≤ i ≤ n if aM < ai then we set fa = fa + aM and then set M = i.

Calculate the sum of fa over all n! permutations of the array a modulo 109 + 7.

Note: two elements are considered different if their indices differ, so for every array a there are exactly n! permutations.

先排好序, 考虑$a[i]$的贡献, 显然除了$a[i]$以外所有$\ge a[i]$的数要全部排在$a[i]$前面才能有贡献, 即$\binom{n}{n-i+1}(n-i)!(i-1)!=\frac{n!}{n-i+1}$

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, a[N], f[N]; int main() {
scanf("%d", &n);
ll fac = 1, ans = 0;
REP(i,1,n) scanf("%d",a+i), fac=fac*i%P;
sort(a+1,a+1+n);
REP(i,1,n) {
if (a[i]==a[n]) break;
if (a[i]==a[i-1]) ans+=f[i]=f[i-1];
else ans+=f[i]=fac*inv(n-i+1)%P*a[i]%P;
}
printf("%lld\n",ans%P);
}

最新文章

  1. jQuery种种
  2. 【学习篇:他山之石,把玉攻】JavaScript Date() 对象 及 格式化
  3. linux fdisk命令使用
  4. codeforces480E Parking Lot
  5. RTC系统
  6. 数据库连接工具类——包含取得连接和关闭资源 ConnUtil.java
  7. 四大主流云平台对比--CloudStack, Eucalyptus, vCloud Director和OpenStack。
  8. js简版定时器
  9. (五)backbone - DEMO - 通信录改造之使用requirejs
  10. Android Dialog详解
  11. 6个最佳的开源Python应用服务器
  12. MyBatis部分细节归档
  13. 基于mykernel完成多进程的简单内核
  14. loadrunner笔记(二):飞机订票系统--客户信息注册
  15. Git中修复bug
  16. 如何在Linux下写无线网卡的驱动【转】
  17. Nodejs+mysql+Express: 一个简单的博客
  18. Yii验证码简单使用及
  19. sql心跳
  20. Linux命令学习与使用2

热门文章

  1. Docker进阶-快速扩容
  2. 20165213 Exp6 信息搜集与漏洞扫描
  3. wait/notify模拟连接池
  4. Winform使用ML.NET时无法加载 DLL“CpuMathNative”问题的解决方法
  5. 编译内核时报错./include/net/sch_generic.h:535:28: error: inlining failed in call to always_inline &#39;qdisc_pkt_len&#39;: indirect function call with a yet undetermined callee static inline unsigned int qdisc_pkt_
  6. leetcode315 计算右侧小于当前元素的个数
  7. js获取当前时间,并格式化为&quot;yyyy-MM-dd HH:mm:ss&quot;
  8. easy dragging script
  9. 机器学习:gensim之Word2Vec 详解
  10. HTML中Data的数据类型