排列组合

 #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. DataGridView 定位到指定行

    //定位到指定行(样式)dataGridView1.ClearSelection();dataGridView1.Rows[selectIndex].Selected = true; //让指定行处于 ...

  2. Selenium3+python自动化013-操作浏览器的Cookie

    为什么要用Cookie?在测试多个页面时候可绕过验证码输入,直接添加cookie,也可以在添加唯一标识时候使用. 一.操作浏览器的Cookie 1.1.验证码的处理方式 说明:WebDriver类库中 ...

  3. yii csrf 配置

    csrf默认启用 全局配置 'components'=>array( 'request'=>array( // Enable Yii Validate CSRF Token 'enable ...

  4. 1.spring异常:Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr ...

  5. pytorch之max()函数

    pytorch之max()函数 待办 返回对应给定中最大值的索引,方便进行和target结果的索引进行比较 索引方式见下 https://blog.csdn.net/liuweiyuxiang/art ...

  6. 题解 【Codeforces988E】Divisibility by 25

    本题是数论好题! 首先我们需要了解一个关于数论的性质: 一个数只要后两位能被25(或4)整除,这个数就能被25(或4)整除. 同理,后三位:(或8).后四位:(或16)亦是如此. 所以,我们只需要判断 ...

  7. 【填坑】python3 manage.py migrate:?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'

    问题: WARNINGS:?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'        H ...

  8. [CCPC2019秦皇岛] F. Forest Program

    [CCPC2019秦皇岛 F] Link https://codeforces.com/gym/102361/problem/F Description 给定一个仙人掌,删去一些边可以让它变成一个森林 ...

  9. JAVA 注解教程(二)元注解

    简介 元注解是可以注解到注解上的注解,或者说元注解是一种基本注解,但是它能够应用到其它的注解上面 元注解有 @Retention.@Documented.@Target.@Inherited.@Rep ...

  10. Ubuntu卸载软件Firefox

    查找火狐详细内容: dpkg --get-selections |grep firefox  删除 sudo apt-get purge firefox*