-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspoj-chefinsq.cpp
174 lines (139 loc) · 2.69 KB
/
spoj-chefinsq.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
const int N = 2e5 + 11;
int n, k;
int _min = INT32_MAX;
int res = 0;
void generateSubseqPrint(int li[], vector<int> current_array, int index, int count)
{
if (count == k)
{
int sum = 0;
for (int i = 0; i < current_array.size(); i++)
{
cout << current_array[i] << " ";
}
cout << endl;
return;
}
for (int i = index; i < n; i++)
{
current_array.push_back(li[i]);
generateSubseqPrint(li, current_array, index + i + 1, count + 1);
current_array.pop_back();
}
}
void generateSubseq(int li[], vector<int> current_array, int index, int count)
{
if (count == k)
{
int sum = 0;
for (int i = 0; i < current_array.size(); i++)
{
sum += current_array[i];
}
if (sum <= _min)
{
if (sum != _min)
{
res = 0;
}
_min = sum;
res++;
}
return;
}
for (int i = index; i < n; i++)
{
current_array.push_back(li[i]);
generateSubseq(li, current_array, index + i + 1, count + 1);
current_array.pop_back();
}
}
void solve()
{
cin >> n >> k;
vector<int> arr;
int li[n];
for (int i = 0; i < n; i++)
{
cin >> li[i];
}
_min = INT32_MAX;
res = 0;
generateSubseq(li, arr, 0, 0);
cout << res << endl;
}
int main()
{
freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int no_of_test_cases;
cin >> no_of_test_cases;
// no_of_test_cases = 1;
while (no_of_test_cases--)
{
solve();
}
return 0;
}
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
// Anand Jaisingh
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> base;
typedef long double ld;
typedef long long ll;
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int maxn=(int)(2e5+5);
const ll mod=(ll)(1e9+7);
int a[maxn];
ll dp[55][55];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
freopen("input.txt", "r", stdin);
int t;cin>>t;
dp[0][0]=1;
for(int i=1;i<51;i++)
{
dp[i][0]=1;
for(int j=1;j<51;j++)
{
dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
}
}
while(t>0)
{
int n,k;
cin>>n>>k;map<int,int> m1;
for(int i=0;i<n;i++)
{
cin>>a[i];
m1[a[i]]++;
}
sort(a,a+n);
int ptr=k-1,val=0;
while(ptr>=0 && a[ptr]==a[k-1])
{
ptr--;val++;
}
ll res=dp[m1[a[k-1]]][val];
cout<<res<<endl;
t--;
}
return 0;
}