-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathable_amount.cpp
More file actions
44 lines (40 loc) · 807 Bytes
/
able_amount.cpp
File metadata and controls
44 lines (40 loc) · 807 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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
vector<int> makable;
vector<bool> visited;
void isMakable(int cnt, int candi) {
for (int i = cnt; i < v.size(); i++) {
if (!visited[i] && find(makable.begin(),makable.end(), candi+v[i])==makable.end()) {
visited[i] = true;
makable.push_back(candi + v[i]);
isMakable(i, candi + v[i]);
visited[i] = false;
}
}
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
v.push_back(a);
visited.push_back(false);
}
sort(v.begin(), v.end());
int answer = 1;
isMakable(0, 0);
sort(makable.begin(), makable.end());
while (true) {
if (find(makable.begin(), makable.end(), answer)==makable.end()) {
break;
}
else {
answer++;
}
}
cout << answer;
}