Skip to content

Commit 2ea70ae

Browse files
authored
[BOJ] 17127 벚꽃이 정보 섬에 피어난 이유 (S5)
1 parent 06cd8be commit 2ea70ae

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

정건우/11주차/260310.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//https://www.acmicpc.net/problem/17127
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.StringTokenizer;
6+
7+
public class BOJ_S5_17127_벚꽃이정보섬에피어난이유 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
int N = Integer.parseInt(br.readLine());
12+
int [] trees = new int[N];
13+
14+
StringTokenizer st = new StringTokenizer(br.readLine());
15+
for (int i = 0; i < N; i++) {
16+
trees[i] = Integer.parseInt(st.nextToken());
17+
}
18+
19+
int max = 0;
20+
21+
// i: 기준점 1
22+
for (int i = 1; i < N; i++) {
23+
int a = 1;
24+
for (int x = 0; x < i; x++) {
25+
a *= trees[x];
26+
}
27+
28+
// j: 기준점 2
29+
for (int j = i+1; j < N; j++) {
30+
int b = 1;
31+
for (int x = i; x < j; x++) {
32+
b *= trees[x];
33+
}
34+
35+
// k: 기준점 3
36+
for (int k = j+1; k < N; k++) {
37+
int c = 1;
38+
for (int x = j; x < k; x++) {
39+
c *= trees[x];
40+
}
41+
42+
int d = 1;
43+
for (int x = k; x < N; x++) {
44+
d *= trees[x];
45+
}
46+
47+
int sum = a + b + c + d;
48+
max = Math.max(max, sum);
49+
}
50+
}
51+
}
52+
53+
System.out.println(max);
54+
55+
56+
}
57+
}

0 commit comments

Comments
 (0)