#include<iostream>
#include<algorithm>
using namespace std;
int n;
int sticker[2][100001];
int stickercal[2][100001];
int stickercount() {
stickercal[0][0] = sticker[0][0];
stickercal[1][0] = sticker[1][0];
stickercal[0][1] = sticker[1][0] + sticker[0][1];
stickercal[1][1] = sticker[0][0] + sticker[1][1];
for (int i = 2; i < n; i++) {
stickercal[0][i] = sticker[0][i] + max(stickercal[1][i - 1], stickercal[1][i - 2]);
stickercal[1][i] = sticker[1][i] + max(stickercal[0][i - 1], stickercal[0][i - 2]);
}
return max(stickercal[0][n-1], stickercal[1][n-1]);
}
int main(void) {
int test_case;
cin >> test_case;
for (int k = 0; k < test_case; k++) {
cin >> n;
int sum = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> sticker[i][j];
}
}
cout << stickercount() << endl;
}
}
'백준 알고리즘 > 다이나믹 프로그래밍' 카테고리의 다른 글
백준 11057번 C++ (0) | 2019.01.17 |
---|---|
백준 9461번 C++ (0) | 2019.01.17 |
백준 1010번 C++ (0) | 2019.01.15 |
백준 2156번 C++ (0) | 2019.01.15 |
백준 11726번 C++ (0) | 2019.01.15 |