-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14225.cpp
More file actions
75 lines (65 loc) · 1.25 KB
/
14225.cpp
File metadata and controls
75 lines (65 loc) · 1.25 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, num;
vector<int> numbers;
vector<int> vc;
vector<int> counts;
void DFS(int depth); // 부분수열의 경우의 수를 찾는다
int MIN(); // 부분수열의 합으로 나올 수 없는 가장 작은 자연수를 찾는다
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num; numbers.push_back(num);
}
if (n == 1) {
if (num == 1) {
cout << 2;
}
else {
cout << 1;
}
}
else {
for (m = 1; m <= n; m++) {
DFS(0);
vc.clear();
}
cout << MIN();
}
return 0;
}
void DFS(int depth) {
if (vc.size() == m) {
int sum = 0;
for (auto i : vc) sum += i;
counts.push_back(sum);
}
for (int i = depth; i < n; i++) {
vc.push_back(numbers[i]);
DFS(i + 1);
vc.pop_back();
}
}
int MIN() {
sort(counts.begin(), counts.end());
if (counts[0] > 1) return 1;
else {
for (int i = 0; i < counts.size() - 1; i++) { // return값이 양수이어야 함
if (i == counts.size() - 2) {
if (counts[i + 1] - counts[i] <= 1) {
if (counts[i + 1] <= 0) return 1;
else return counts[i + 1] + 1;
}
else return counts[i] + 1;
}
else {
if (counts[i + 1] - counts[i] > 1) {
if (counts[i + 1] <= 0) continue;
else return counts[i] + 1;
}
}
}
}
}