-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path697E.cpp
More file actions
82 lines (81 loc) · 1.5 KB
/
697E.cpp
File metadata and controls
82 lines (81 loc) · 1.5 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod = 1000000000 + 7;
long long int arr[1000 + 1];
ll bigmod(ll a, ll b)
{
if (a == 0)
return 1;
ll product = 1;
while (b > 0)
{
if (b & 1)
{
product *= a;
b--;
product %= mod;
}
a *= a;
a %= mod;
b /= 2;
}
return product;
}
ll nCr(ll n, ll r)
{
if(n<r)return 0;
if(n==r)return 1;
ll a = arr[r];
a = bigmod(arr[r],mod-2)%mod;
ll b = bigmod(arr[n-r],mod-2)%mod;
a*= b;
a %= mod;
a *= arr[n];
a %= mod;
return a;
}
int main()
{
int t;
scanf("%d", &t);
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i <= 1000; i++)
{
arr[i] = i * arr[i - 1];
arr[i]%=mod;
}
while (t--)
{
int n,k;
// int cnt[1000+1];
// memset(cnt,0,sizeof(cnt));
scanf("%d %d", &n, &k);
int a[n];
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
// cnt[a[i]]++;
}
sort(a,a+n);
reverse(a,a+n);
int p = a[k-1];
int cnt = 0;
int cnt2 = 0;
for (int i = 0; i < n; i++)
{
if(a[i]==p){
cnt++;
if(i < k){
cnt2++;
}
}
else if(a[i] < p){
break;
}
}
ll ans = nCr(cnt,cnt2);
printf("%lld\n",ans);
}
}