-
Notifications
You must be signed in to change notification settings - Fork 1
/
p9465.java
29 lines (28 loc) · 1.06 KB
/
p9465.java
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
import java.io.*;
import java.util.*;
public class p9465 {
static int n;
static int dp[][];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
int t = Integer.parseInt(br.readLine());
int[][] stick = new int[2][t+1];
dp = new int[2][t+1];
for (int j = 0; j < 2; j++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int k = 1; k <= t; k++) {
stick[j][k] = Integer.parseInt(st.nextToken());
}
}
dp[0][1] = stick[0][1];
dp[1][1] = stick[1][1];
for (int j = 2; j <= t; j++) {
dp[0][j] = Math.max(dp[1][j-1], dp[1][j-2]) + stick[0][j];
dp[1][j] = Math.max(dp[0][j-1], dp[0][j-2]) + stick[1][j];
}
System.out.println(Math.max(dp[0][t], dp[1][t]));
}
}
}