BOJ::9465 스티커
https://www.acmicpc.net/problem/9465
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 | #include <stdio.h> using namespace std; int t, n; int a[100000][2]; int d[100000][2]; int max(int a, int b) { return (a > b) ? a : b; } int main() { scanf("%d", &t); for (int tc = 0; tc < t; tc++) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i][0]); } for (int i = 0; i < n; i++) { scanf("%d", &a[i][1]); } d[0][0] = a[0][0]; d[0][1] = a[0][1]; d[1][0] = a[1][0] + d[0][1]; d[1][1] = a[1][1] + d[0][0]; for (int i = 2; i < n; i++) { d[i][0] = a[i][0] + max(d[i - 1][1], d[i - 2][1]); d[i][1] = a[i][1] + max(d[i - 1][0], d[i - 2][0]); } printf("%d\n", max(d[n - 1][0], d[n - 1][1])); } return 0; } | cs |
'BOJ::문제풀이' 카테고리의 다른 글
10164 격자상의 경로 (0) | 2018.01.06 |
---|---|
9466 텀 프로젝트 (0) | 2018.01.06 |
7576 토마토 (0) | 2018.01.06 |
7562 나이트의 이동 (0) | 2018.01.06 |
6603 로또 (0) | 2018.01.06 |