File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-08/sol/Naman2251 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments