-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16198.cpp
More file actions
50 lines (45 loc) · 959 Bytes
/
16198.cpp
File metadata and controls
50 lines (45 loc) · 959 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
// 16198. 에너지 모으기
// 2019.12.26
// 브루트 포스
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
int ans = 0;
void go(int cnt, int value, vector<int>& marble)
{
// 종료조건
if (cnt == n - 2)
{
ans = max(ans, value);
return;
}
// 차례대로 구슬을 선택한다.
for (int i = 1; i < marble.size() - 1; i++)
{
vector<int> tmp;
// 선택한 구슬을 제거하고 다시 번호를 매긴다.
for (int j = 0; j < marble.size(); j++)
{
if (j == i)
{
continue;
}
tmp.push_back(marble[j]);
}
go(cnt + 1, value + marble[i - 1] * marble[i + 1], tmp);
}
}
int main()
{
cin >> n;
vector<int>marbles(n);
for (int i = 0; i < n; i++)
{
cin >> marbles[i];
}
go(0, 0, marbles);
cout << ans << "\n";
return 0;
}