728x90
๋ฌธ์
https://www.acmicpc.net/problem/9465
๋ฌธ์ ์ค๋ช
์ฝ๋
#include <iostream>
#include <algorithm>
using namespace std;
int sticker[2][100001];
int searchMaxScore(int);
int main() {
int testcase = 0;
cin >> testcase;
for (int t = 0; t < testcase; t++) {
int column = 0;
cin >> column;
for (int row = 0; row < 2; row++) {
for (int col = 1; col <= column; col++) {//๋ฐ๋ณต๋ฌธ์ index 2๋ถํฐ ์์ํ๊ธฐ ์ํด
cin >> sticker[row][col];
}
}
cout << searchMaxScore(column) << "\n";
}
}
int searchMaxScore(int column) {
for (int i = 2; i <= column; i++) {
//์ ์คํฐ์ปค์ ๊ฒฝ์ฐ์ ์
sticker[0][i] += max(sticker[1][i - 1], sticker[1][i - 2]);
//์๋ ์คํฐ์ปค์ ๊ฒฝ์ฐ์ ์
sticker[1][i] += max(sticker[0][i - 1], sticker[0][i - 2]);
}
return max(sticker[0][column], sticker[1][column]);
}
728x90
'๐ Coding Test Study > Algorithm Problem' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++][BEAKJOON][DP] ๋์ 1 (0) | 2021.09.21 |
---|---|
[C++][BAEKJOON][์๋ฎฌ๋ ์ด์ ] 17144๋ฒ ๋ฏธ์ธ๋จผ์ง ์๋ ! (0) | 2021.09.19 |
[C++][ํ๋ก๊ทธ๋๋จธ์ค] ๊ดํธ ๋ณํ (0) | 2021.08.22 |
[C++][Baekjoon] 14503๋ฒ ๋ก๋ด ์ฒญ์๊ธฐ (0) | 2021.08.22 |
[C++][Baekjoon][DP] 1309๋ฒ ๋๋ฌผ์ (0) | 2021.08.22 |