Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 17127번 - 벚꽃이 정보섬에 피어난 이유 본문
파티션을 활용한 브루트포스 문제
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int n;
int arr[11];
int calc(int start, int end) {
int x = 1;
for (int i = start; i <= end; i++) {
x *= arr[i];
}
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int temp, ans = 0;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
temp = calc(1, i) + calc(i + 1, j) + calc(j + 1, k) + calc(k + 1, n);
ans = max(ans, temp);
}
}
}
cout << ans << endl;
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 23304번 - 아카라카 (0) | 2022.05.13 |
|---|---|
| [C++] 백준 1753 - 최단경로 (0) | 2022.05.11 |
| [C++] 백준 10552번 - DOM (0) | 2022.05.03 |
| [C++] 백준 13565번 - 침투 (0) | 2022.05.03 |
| [C++] 백준 14464번 - 소가 길을 건너간 이유 4 (0) | 2022.04.27 |
Comments