• 题意:给你一长度为\(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. 了解一下ajax

    AJAX:是一种无需重新加载页面的情况下能够更新部分(局部更新)网页的技术. 1. 概念:ASychronous JavaScript And XML 异步的JavaScript和XML 首先了解一下 ...

  2. 【Software Test】Basic Of ST

    文章目录 Learning Objective Introduction Software Applications Before Software Testing What is testing? ...

  3. ps的参数解释

    [root@bogon ~]# ps axuUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND user启动进程的用户 pid  表示进程标志 ...

  4. Java 安全之Weblogic 2018-2628&2018-2893分析

    Java 安全之Weblogic 2018-2628&2018-2893分析 0x00 前言 续上一个weblogic T3协议的反序列化漏洞接着分析该补丁的绕过方式,根据weblogic的补 ...

  5. 【VNC】vnc远程连接的时候无法显示图像已解决

    介绍一个 VNC连接工具:iis7服务器管理工具 IIs7服务器管理工具可以批量连接并管理VNC服务器 作为服务器集成管理器,它最优秀的功能就是批量管理windows与linux系统服务器.vps.能 ...

  6. VL02N发货过账BAPI

    使用BAPI函数: BAPI_OUTB_DELIVERY_CONFIRM_DEC 进行delivery的发货过账,可能会有如此的需求,就是修改实际的发货日期.规划的GI.交货日期.装载日期.传输计划日 ...

  7. Flask的“中间件”

    特殊装饰器 from flask import Flask,render_template,request app = Flask(__name__) @app.before_request def ...

  8. thinkphp如何实现伪静态

    去掉 URL 中的 index.php ThinkPHP 作为 PHP 框架,是单一入口的,那么其原始的 URL 便不是那么友好.但 ThinkPHP 提供了各种机制来定制需要的 URL 格式,配合 ...

  9. jQuery 点击input框标题收起

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. session和cookie自动登录机制

    cookie的存储 cookie是浏览器支持的一种本地存储方式.以dict,键值对方式存储. {"sessionkey": "123"} 浏览器会自动对于它进行 ...