File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-02/BEESA_MANISH Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ TC - O(N^2)
3+ SC - O(N^2)
4+ */
5+
6+
7+ #include < iostream>
8+ #include < vector>
9+ #include < algorithm>
10+ #include < map>
11+
12+ using namespace std ;
13+ long long C[1005 ][1005 ];
14+ const int MOD = 1e9 + 7 ;
15+ void precompute () {
16+ for (int i = 0 ; i <= 1000 ; i++) {
17+ C[i][0 ] = 1 ;
18+ for (int j = 1 ; j <= i; j++) {
19+ C[i][j] = (C[i - 1 ][j - 1 ] + C[i - 1 ][j]) % MOD;
20+ }
21+ }
22+ }
23+
24+ void solve () {
25+ int n, k;
26+ cin >> n >> k;
27+ vector<int > a (n);
28+ map<int , int > total_freq;
29+
30+ for (int i = 0 ; i < n; i++) {
31+ cin >> a[i];
32+ total_freq[a[i]]++;
33+ }
34+
35+ sort (a.rbegin (), a.rend ());
36+
37+ int v = a[k - 1 ];
38+ int needed_count = 0 ;
39+
40+ for (int i = 0 ; i < k; i++) {
41+ if (a[i] == v) needed_count++;
42+ }
43+
44+ int total_count = total_freq[v];
45+
46+ cout << C[total_count][needed_count] << " \n " ;
47+ }
48+
49+ int main () {
50+
51+ precompute ();
52+
53+ int t;
54+ cin >> t;
55+ while (t--) {
56+ solve ();
57+ }
58+ return 0 ;
59+ }
You can’t perform that action at this time.
0 commit comments