• 题意:给你一长度为\(n\)的序列(可能含有相等元素),你要找到\(m\)个位置不同的元素使得\(max(a_{i-1},a_{i_2},...,a_{i_m})-min(a_{i-1},a_{i_2},...,a_{i_m})\le k\),问你共有多少种不同的元祖满足条件,对答案\(mod 1e9+7\).
  • 题解:我们可以先用map做桶统计每个数出现的次数,然后枚举\([1,n]\),用前缀和\(pre\)统计出现的次数,然后我们再去枚举\([1,n]\),我们每次将\(i\)和\([1,i-1]\)看成两部分,从\(i\)和\([1,i-1]\)中选数,这样可以做到不重复不漏选,每次枚举从\(i\)中选的次数和\([1,i-1]\)选的次数求组合数即可.
  • 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;} int t;
int n,m,k;
int a[N];
int f[N],inv[N];
int pre[N];
map<int,ll> mp; int add(int x,int y){
x+=y;
if(x>=mod) x-=mod;
return x;
} int mul(int x,int y){
return 1ll*x*y%mod;
} int fpow(int a,int b){
int res=1;
while(b){
if(b&1) res=mul(res,a);
a=mul(a,a);
b>>=1;
}
return res;
} int C(int n, int m){
if(n<m) return 0;
return mul(f[n],mul(inv[n-m],inv[m]));
} int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t; f[0]=1;
rep(i,1,N-1) f[i]=mul(f[i-1],i);
inv[N-1]=fpow(f[N-1],mod-2);
per(i,N-2,0) inv[i]=mul(inv[i+1],i+1); while(t--){
cin>>n>>m>>k; mp.clear(); rep(i,1,n){
cin>>a[i];
mp[a[i]]++;
} if(m==1){
cout<<n<<'\n';
continue;
} rep(i,1,n){
pre[i]=pre[i-1]+mp[i];
} ll ans=0; rep(i,1,n){
int cur=mp[i];
if(!cur) continue;
int psum=pre[i-1]-((i-k-1>=0)?pre[i-k-1]:0);
rep(j,1,min(cur,m)) ans=add(ans,mul(C(cur,j),C(psum,m-j)));
} rep(i,1,n) pre[i]=0; cout<<ans<<'\n'; } return 0;
}

Codeforces Round #690 (Div. 3) E2. Close Tuples (hard version) (数学,组合数)的更多相关文章

  1. Codeforces Round #690 (Div. 3)

    第一次 ak cf 的正式比赛,不正式的是寒假里 div4 的 Testing Round,好啦好啦不要问我为什么没有 ak div4 了,差一题差一题 =.= 不知不觉已经咕了一个月了2333. 比 ...

  2. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  3. CodeForces -Codeforces Round #496 (Div. 3) E2. Median on Segments (General Case Edition)

    参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意 ...

  4. Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)

    https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...

  5. Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)

    E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...

  6. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

  7. Codeforces Round #828 (Div. 3) E2. Divisible Numbers (分解质因子,dfs判断x,y)

    题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a ...

  8. Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学

    D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...

  9. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数

    D. Soldier and Number Game Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

随机推荐

  1. Haproxy-1.8.20 根据路径(URI)转发到后端不同集群

    HAProxy根据不同的URI 转发到后端的服务器组 1 ) 实验内容说明: 1.1 ) 根据不同的URI 转发到后端的服务器组. /a /b 和其他 默认使用其他. 1.2 ) 使用IP介绍: ha ...

  2. 【译】Async/Await(一)——多任务

    原文标题:Async/Await 原文链接:https://os.phil-opp.com/async-await/#multitasking 公众号: Rust 碎碎念 翻译 by: Praying ...

  3. 2.jmeter组件介绍

    jmeter默认语言设置:  1.临时设置: 进入options -- Choose Language -- 选择中文简体,设置后语言  切换成中文,重启失效  2.永久设置:进入jmeter目录下的 ...

  4. Log4j配置按照文件大小和日期分割日志文件

    目录 Log4j 下载地址 文件大小分割日志文件 以日期分割每天产生一个日志文件 自定义信息输出到日志文件 Log4j 下载地址 Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控 ...

  5. CopyOnWriteArrayList 读写分离,弱一致性

    为什么会有CopyOnWriteArrayList? 我们知道ArrayList和LinkedList实现的List都是非线程安全的,于是就有了Vector,它是基于ArrayList的线程安全集合, ...

  6. 敏感信息泄露 - Pikachu

    概述: 由于后台人员的疏忽或者不当的设计,导致不应该被前端用户看到的数据被轻易的访问到. 比如:---通过访问url下的目录,可以直接列出目录下的文件列表;---输入错误的url参数后报错信息里面包含 ...

  7. px转rem的填坑之路

    这是要为一个vue项目做自适应,设计稿是1920*1080的,要适应各种手机.ipad.3840*2160的超大屏,所以就选择了rem,包用的是 postcss-pxtorem 在适配的时候遇到了很多 ...

  8. powershell中的cmdlet命令

    Add-Computer 向域或工作组中添加计算机. Add-Content 向指定的项中添加内容,如向文件中添加字词. Add-History 向会话历史记录追加条目. Add-Member 向 W ...

  9. LeetCode-P53题解【动态规划】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: https://leetcode.com/problems/maximum-subarray/ ...

  10. 导出exe的经验

    安装pyinstaller 首先要找到scripts的绝对路径(主要是找到scripts就行了 先是安装C:\Users\96290\AppData\Local\Programs\Python\Pyt ...