Skip to content

Commit 54498e4

Browse files
authored
Merge pull request #495 from Naman2251/main
day8sol2
2 parents 84975bf + c3cf9ec commit 54498e4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//Submission Link: https://codeforces.com/contest/1999/submission/356264212
2+
3+
/*
4+
First I counted the number of one and zeros then I calculated the permutation possible for getting k element using one or zero. THen by
5+
applying pnc calculated the number of subsequences.
6+
*/
7+
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
11+
12+
const long long mod=1e9+7;
13+
14+
vector<long long> fact(200001);
15+
16+
long long binexp(long long a, long long b) {
17+
long long ans = 1;
18+
a %= mod;
19+
while (b) {
20+
if (b & 1) ans = ans * a % mod;
21+
a = a * a % mod;
22+
b >>= 1;
23+
}
24+
return ans%mod;
25+
}
26+
27+
long long C(long long n, long long r) {
28+
if (r < 0 || r > n) return 0;
29+
long long ans=fact[n] * binexp(fact[r], mod - 2) % mod;
30+
ans*=binexp(fact[n - r], mod - 2) % mod;
31+
return ans%mod;
32+
}
33+
34+
int main() {
35+
fastio;
36+
fact[0]=1;
37+
for(long long i=1; i<200001; i++) fact[i]=(fact[i-1]*i)%mod;
38+
long long t;
39+
cin>>t;
40+
while(t--) {
41+
long long n, k;
42+
cin>>n>>k;
43+
vector<int> a(n), cnt(2,0);
44+
for(int i=0; i<n; i++) {
45+
cin>>a[i];
46+
cnt[a[i]]++;
47+
}
48+
long long ans=0;
49+
for(long long i=0; i<=cnt[0]; i++) {
50+
int b=k-i;
51+
if(b>=0 && b<=cnt[1]) {
52+
if(b>i) ans+=(C(cnt[0], i)%mod)*(C(cnt[1], b)%mod)%mod;
53+
}
54+
}
55+
cout<<ans%mod<<endl;
56+
}
57+
}

0 commit comments

Comments
 (0)