Skip to content

Commit ffa55d8

Browse files
committed
BOJ_9465 : 스티커
1 parent 12646fe commit ffa55d8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

week6/BOJ_9465(스티커).java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int T = Integer.parseInt(br.readLine());
9+
for(int tc=0; tc<T; tc++) {
10+
int N = Integer.parseInt(br.readLine());
11+
int[][] sticker = new int[3][N+1];
12+
for(int i=0; i<2; i++) {
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
for(int j=0; j<N; j++) {
15+
sticker[i][j] = Integer.parseInt(st.nextToken());
16+
}
17+
}
18+
// d[0][i] = 윗줄 스티커만 뜯는 경우
19+
// d[1][i] = 아랫줄 스티커만 뜯는 경우
20+
// d[2][i] = 스티커를 떼지 않는 경우
21+
int[][] d = new int[3][N+1];
22+
d[0][0] = sticker[0][0];
23+
d[1][0] = sticker[1][0];
24+
for(int i=1; i<=N; i++) {
25+
d[0][i] = Math.max(d[1][i-1], d[2][i-1]) + sticker[0][i];
26+
d[1][i] = Math.max(d[0][i-1], d[2][i-1]) + sticker[1][i];
27+
d[2][i] = Math.max(d[0][i-1], Math.max(d[1][i-1], d[2][i-1]));
28+
}
29+
System.out.println(Math.max(d[0][N], d[1][N]));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)