-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10819.cpp
More file actions
49 lines (48 loc) · 828 Bytes
/
10819.cpp
File metadata and controls
49 lines (48 loc) · 828 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
using namespace std;
int mx = -10000;
int n;
int chk[9];
vector<int> v;
int dfs(int idx, int cnt, int sum)
{
if(cnt==n)
{
if(sum>mx) mx = sum;
return 0;
}
for (int i = 0; i < n; ++i)
{
if(chk[i]==0)
{
chk[i] = 1;
dfs(i,cnt+1,sum + abs((v[idx]-v[i])));
chk[i] = 0;
}
}
return 0;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int num;
cin>>n;
for (int i = 0; i < n; ++i)
{
cin>>num;
v.push_back(num);
}
for (int i = 0; i < n; ++i)
{
chk[i] = 1;
dfs(i,1,0);
chk[i] = 0;
}
cout<<mx<<"\n";
}