-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path574.cpp
More file actions
36 lines (35 loc) · 812 Bytes
/
574.cpp
File metadata and controls
36 lines (35 loc) · 812 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
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int array[20];
int n, f;
void check(int remain, int m) {
int i;
if (remain == 0) {
for (i = 0; i < v.size(); i++) {
if (i != 0) printf("+");
printf("%d", v[i]);
}
puts("");
f = 1;
return;
}
for (i = m; i < n; i++) {
if (i == m || array[i] != array[i - 1]) {
v.push_back(array[i]);
check(remain - array[i], i + 1);
v.pop_back();
}
}
}
int main() {
int i, j, k, m;
while (~scanf("%d%d", &m, &n)) {
if (m == 0 && n == 0) return 0;
for (i = 0; i < n; i++) scanf("%d", &array[i]);
f = 0;
printf("Sums of %d:\n", m);
check(m, 0);
if (f == 0) puts("NONE");
}
}