forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODECHEF) Chef and Trump Cards.cpp
69 lines (62 loc) · 1.1 KB
/
(CODECHEF) Chef and Trump Cards.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
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define MOD 1000000007
ll pwr(ll a, ll b){
ll res=1;
while(b != 0){
if(b&1)
res=res*a%MOD;
b >>= 1;
a=a*a%MOD;
}
return res;
}
ll los(ll n ,ll r){
ll res=1;
ll k = min(r,n-r);
for(int i=0;i<k;i++) {
res=(res%MOD*(n-i)%MOD)%MOD;
res = (res%MOD*(pwr(i+1,MOD-2)%MOD))%MOD;
}
return res%MOD;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
//**********************
ll T, N, maxfreq, ans, maxno;
cin >> T;
while(T--) {
cin >> N;
ll A[N];
for(ll i = 0; i < N; ++i)
cin >> A[i];
maxno = -1;
for(ll i = 0; i < N; ++i) {
if(A[i] > maxno)
maxno = A[i];
}
maxfreq = 0;
for(ll i = 0; i < N; ++i) {
if(maxno == A[i])
maxfreq++;
}
if(N == 1)
ans = 2;
else {
if(maxfreq&1) {
ans = pwr(2, N)%MOD;
}
else {
ans = pwr(2,N)%MOD;
ans -= ((pwr(2,N-maxfreq)%MOD)*los(maxfreq,maxfreq>>1)%MOD)%MOD;
}
if(ans < 0)
ans = ans+MOD;
}
cout << ans % MOD << "\n";
}
return 0;
}