Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBOJ_9465.java
More file actions
Latest commit
44 lines (35 loc) · 1.24 KB
/
Copy pathBOJ_9465.java
File metadata and controls
44 lines (35 loc) · 1.24 KB
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
packagealgorithm_study.april.day_04_16;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.StringTokenizer;
publicclassBOJ_9465 {
privatestaticint[][] stickers;
privatestaticint[][] dp;
privatestaticintn;
publicstaticvoidmain(String[] args) throwsNumberFormatException, IOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
StringTokenizerst;
intT = Integer.parseInt(br.readLine());
for (inttest_case = 1; test_case <= T; test_case++) {
n = Integer.parseInt(br.readLine());
stickers = newint[2][n + 1];
dp = newint[2][n + 1];
for (intr = 0; r < 2; r++) {
st = newStringTokenizer(br.readLine());
for (intc = 1; c <= n; c++) {
stickers[r][c] = Integer.parseInt(st.nextToken());
}
}
dp[0][0] = 0;
dp[1][0] = 0;
dp[0][1] = stickers[0][1];
dp[1][1] = stickers[1][1];
for (inti = 2; i <= n; i++) {
dp[0][i] = Math.max(dp[1][i - 1] + stickers[0][i], dp[1][i - 2] + stickers[0][i]);
dp[1][i] = Math.max(dp[0][i - 1] + stickers[1][i], dp[0][i - 2] + stickers[1][i]);
}
System.out.println(Math.max(dp[0][n], dp[1][n]));
}
}
}