排列组合

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
const long long mod = 1e9+;
long long inv[];
long long qpow(int p,int q){
long long s=;
for(;q;q>>=,p=1ll*p*p%mod)
if(q&)
s=1ll*s*p%mod;
return s;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
for(int i=;i<=n;++i)
cin>>a[i];
sort(a+,a++n);
for(int i=;i<=n;++i)
inv[i]=qpow(i,mod-);
long long sum=;
long long temp=;
for(int i=k;i<=n;++i){
sum=(sum+a[i]*temp%mod)%mod;
temp=temp*i%mod;
temp=temp*inv[i+-k]%mod;
}
temp=;
for(int i=n-k+;i;--i){
sum=(sum+mod-a[i]*temp%mod)%mod;
temp=temp*(n-i+)%mod;
temp=temp*inv[n-i+-k]%mod;
}
cout<<sum;
return ;
}

Atcoder Beginner Contest151E(排列组合)的更多相关文章

  1. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  2. [Agc028B]Removing Blocks_排列组合

    Removing Blocks 题目链接:https://atcoder.jp/contests/agc028/tasks/agc028_b 数据范围:略. 题解: 这种问题的第一步很套路,就是对于每 ...

  3. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  4. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  5. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  6. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

  7. .NET平台开源项目速览(11)KwCombinatorics排列组合使用案例(1)

    今年上半年,我在KwCombinatorics系列文章中,重点介绍了KwCombinatorics组件的使用情况,其实这个组件我5年前就开始用了,非常方便,麻雀虽小五脏俱全.所以一直非常喜欢,才写了几 ...

  8. 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  9. 【原创】开源.NET排列组合组件KwCombinatorics使用(二)——排列生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

随机推荐

  1. 常用的H5代码

    1.返回上一页第一次在手机端用到返回上一页的时候,只写了window.history.go(-1):这一句.但是只在安卓手机有效果,兼容苹果手机需要在跳转代码后加上return false:这句.跳转 ...

  2. HBuilderX开发app实现自动更新版本

      需求说明:使用MUI+Vue等技术并且通过HBuilderX打包开发移动app,在有版本更新时需要自动提示用户有新版本,并且可以点击下载自动安装. 思路说明: 应用打开时(使用Vue的生命周期mo ...

  3. SpringBoot学习- 5、整合Redis

    SpringBoot学习足迹 SpringBoot项目中访问Redis主要有两种方式:JedisPool和RedisTemplate,本文使用JedisPool 1.pom.xml添加dependen ...

  4. appium+android测试环境安装

    1. jdk配置 一.背景 JDK已经更新到12了,但是由于很多工具仍然未及时更新,故推荐最稳定的JDK版本1.8.x: JDK需要配置通常情况下,JDK配置分为三项: JAVA_HOME:某些软件仍 ...

  5. BibTex 学习笔记

    BibTex 学习笔记 使用BibTex 来管理参考文献:一次管理,终身使用! 1. 定义 BibTeX 是一个使用数据库的的方式来管理参考文献程序, 用于协调LaTeX的参考文献处理. BibTeX ...

  6. Python2安装MySQLdb

    在http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python下载对应的包版本,如果是win7 64位2.7版本的python,就下载 MySQL_p ...

  7. layer iframe 设置关闭按钮 和刷新

    layer.open({ type: 2, title: 'XXXX网吧历史更多数据', shade:0, // closeBtn:0, resize:false, move:false, shade ...

  8. C# ODP.Net oracle数据库操作 支持不安装客户端

    下载: http://download.oracle.com/otn/other/ole-oo4o/ODTwithODAC1110720.zip?AuthParam=1414811820_e61f2f ...

  9. .net 文件接口的封装,写日志,创建文件log

    public class FileSupport { public static FileSupport Instance = new FileSupport(); public static str ...

  10. A New Recurrence-Network-Based Time Series Analysis Approach for Characterizing System Dynamics - Guangyu Yang, Daolin Xu * and Haicheng Zhang

    Purpose: characterize the evolution of dynamical systems. In this paper, a novel method based on eps ...