-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10819.cpp
More file actions
40 lines (31 loc) · 711 Bytes
/
10819.cpp
File metadata and controls
40 lines (31 loc) · 711 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
#include <iostream>
#include <vector>
using namespace std;
int N;
int arr[8 + 1];
bool check[8 + 1] = {false, };
int ans = 0;
void dfs(int pre, int now, int cnt, int sum){
if(cnt == N+1){
ans = max(ans, sum);
return;
}
if(!check[now]){
check[now] = true;
if(pre != now)
sum += abs(arr[pre] - arr[now]);
for(int i = 1; i <= N; i++){
dfs(now, i, cnt + 1, sum);
}
check[now] = false;
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> N;
for(int i = 1; i <= N; i++)
cin >> arr[i];
for(int i = 1; i <= N; i++)
dfs(i, i, 1, 0);
cout << ans;
}