-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10819.cpp
More file actions
57 lines (52 loc) · 946 Bytes
/
BOJ_10819.cpp
File metadata and controls
57 lines (52 loc) · 946 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
// 22 / 1 / 13
#include <iostream>
#include <vector>
using namespace std;
int n, answer;
vector<int> arr;
vector<bool> check;
vector<int> solveArr;
int gapSum()
{
int output = 0;
for (int i = 0; i < n - 1; i++)
{
int x = solveArr[i] - solveArr[i + 1];
if (x > 0)
output += x;
else
output += (-x);
}
return output;
}
void dfs(int level)
{
if (level == n)
{
int x = gapSum();
if (x > answer)
answer = x;
return;
}
for (int i = 0; i < n; i++)
{
if (check[i])
continue;
check[i] = true;
solveArr.push_back(arr[i]);
dfs(level + 1);
check[i] = false;
solveArr.pop_back();
}
}
int main(void)
{
cin >> n;
arr.assign(n, 0);
check.assign(n, false);
for (int i = 0; i < n; i++)
cin >> arr[i];
dfs(0);
cout << answer;
return 0;
}