백준
백준 소스코드 [C++] 16198 에너지 모으기
Hani_Levenshtein
2020. 8. 20. 22:28
https://www.acmicpc.net/problem/16198
16198번: 에너지 모으기
N개의 에너지 구슬이 일렬로 놓여져 있고, 에너지 구슬을 이용해서 에너지를 모으려고 한다. i번째 에너지 구슬의 무게는 Wi이고, 에너지를 모으는 방법은 다음과 같으며, 반복해서 사용할 수 있�
www.acmicpc.net
백준 소스코드 [C++] 16198 에너지 모으기
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int arr[10];
bool check[10];
int energy = 0;
int n;
int chase(int i) {
int a, b;
for (int j = i - 1;0 <= j;j--)
if (check[j] == true)
{ a = arr[j]; break; }
for (int j = i + 1;j < 10;j++)
if (check[j] == true)
{b = arr[j];break;}
return a * b;
}
void charge(int m,int num) {
if (m == 2) {
energy = max(energy, num);
return;
}
for (int i = 1;i < n-1;i++) {
if (check[i] == true) {
check[i] = false;
charge(m - 1, num + chase(i));
check[i] = true;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0;i < n;i++) {
cin >> arr[i];
check[i] = true;
}
int m = n;
charge(m,0);
cout << energy;
return 0;
}