-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathE.cpp
59 lines (57 loc) · 1.07 KB
/
E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#define lli long long int
#define mod 1000000007
#define pi 3.141592653589793238
using namespace std;
lli fact[1001];
lli power(lli a,lli n)
{ lli res=1;
while(n)
{ if(n%2==0)
{ a=(a*a)%mod;
n/=2;
}
else
{ res=(res*a)%mod;
n--;
}
}
return res;
}
lli comb(lli n, lli r)
{ lli denom;
denom=(fact[r]*fact[n-r])%mod;
denom=power(denom,mod-2);
return (fact[n]*denom)%mod;
}
int main()
{ int t;
cin>>t;
//t=1;
fact[0]=1; fact[1]=1;
for(int i=2;i<1001;i++)
fact[i]=(fact[i-1]*i)%mod;
while(t--)
{ lli n,k;
cin>>n>>k;
lli a[n],req=1,total,ans;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n,greater<int>());
int pos=k-2;
while(a[pos]==a[k-1] && pos>=0)
{ req++; pos--;}
pos=k;
total=req;
while(pos<n && a[pos]==a[k-1])
{ total++;pos++;}
ans=comb(total,req);
cout<<ans<<endl;
}
return 0;
}