문제풀이/백준
2156 - 포도주 시식
동바리
2021. 9. 11. 21:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int Max(int a, int b, int c) { | |
if (b > c) { | |
if (a > b) return a; | |
else return b; | |
} | |
else { | |
if (a > c) return a; | |
else return c; | |
} | |
} | |
int main() { | |
int d[10001] = { 0 }, a[10001] = { 0 }; | |
int n; scanf("%d", &n); | |
for (int i = 1; i <= n; i++) scanf("%d", &a[i]); | |
d[1] = a[1]; | |
d[2] = a[1] + a[2]; | |
for (int i = 3; i <= n; i++) | |
d[i] = Max(d[i - 3] + a[i - 1] + a[i], d[i - 1], d[i - 2] + a[i]); | |
printf("%d", d[n]); | |
return 0; | |
} |
문제 :
https://www.acmicpc.net/problem/2156
풀이 :
http://blog.naver.com/PostView.nhn?blogId=occidere&logNo=220791788953