forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHEFANDTRUMPCARDS.CPP
102 lines (90 loc) · 1.92 KB
/
CHEFANDTRUMPCARDS.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// https://www.codechef.com/SEPT20B/problems/CRDGAME2 //
// Babitha's code //
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int power(int x, int y)
{
int res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
{
res = res * x;
res %= mod;
}
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
x%=mod; //x %= mod;
}
return res;
}
unsigned long long power(unsigned long long x,
int y, int p)
{
unsigned long long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n, int p)
{
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
int r, int p)
{
// Base case
if (r == 0)
return 1;
unsigned long long fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int c[n];
map<int,int> m;
int maxi=0;
for (int i = 0; i < n;i++)
{
cin>>c[i];
m[c[i]]++;
maxi=max(maxi,c[i]);
}
int ans=power(2,n);
if(m[maxi]%2==0){
int p=power(2,n-m[maxi]);
p*=nCrModPFermat(m[maxi],m[maxi]/2,mod);
p%=mod;
ans-=p;
ans%=mod;
ans+=mod;
}
ans%=mod;
cout<<ans<<endl;
}
return 0;
}