-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchiamang.cpp
More file actions
63 lines (60 loc) · 899 Bytes
/
chiamang.cpp
File metadata and controls
63 lines (60 loc) · 899 Bytes
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
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
int n, k, sum;
bool ok = 0;
vector<int> a, cb;
vector<bool> dd;
void Try(int s, int tmp) {
if (ok) return;
if (tmp == 0) {
ok = 1;
return;
}
for(int i = 0; i < n; i++) {
if (s == sum) {
Try(0, tmp-1);
continue;
}
if (s > sum) return;
Try(s+a[i], tmp);
}
}
void init() {
sum = 0;
a.clear();
a.resize(n);
cb.clear();
cb.resize(n+1,-1);
dd.clear();
dd.resize(n+1,0);
ok = 0;
}
void solve() {
cin >> n >> k;
init();
for(int i = 0; i < n; i++) {
cin >> a[i];
sum+=a[i];
}
if (sum % k == 0) {
sum/=k;
Try(0,k);
cout<< ok << endl;
}
else cout << 0 << endl;
}
int main(){
faster();
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}