티스토리 뷰
문제 링크
https://www.acmicpc.net/problem/2156
2156번: 포도주 시식
효주는 포도주 시식회에 갔다. 그 곳에 갔더니, 테이블 위에 다양한 포도주가 들어있는 포도주 잔이 일렬로 놓여 있었다. 효주는 포도주 시식을 하려고 하는데, 여기에는 다음과 같은 두 가지 규
www.acmicpc.net

N이 2일 때는 와인의 첫번째와 두번째 값을 더한 값입니다.

N이 3이상일 때는 위와 같이 연속되는 값이 3개가 넘지않는 경우 중
총 3가지의 값 중 최대값이 정답이 됩니다.
구현 코드
This file contains 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 <iostream> | |
#include <algorithm> | |
#define endl '\n' | |
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr) | |
using namespace std; | |
const int MAX = 10001; | |
int wine[MAX]; | |
int dp[MAX]; | |
int main(){ | |
fastio; | |
int n; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> wine[i]; | |
dp[1] = wine[1]; | |
dp[2] = wine[1] + wine[2]; | |
for(int i=3;i<=n;i++){ | |
dp[i] = max(dp[i-1],dp[i-3]+wine[i-1]+wine[i]); | |
dp[i] = max(dp[i],dp[i-2]+wine[i]); | |
} | |
cout << dp[n] << endl; | |
return 0; | |
} |
This file contains 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
n = int(input()) | |
wine = [] | |
wine.append(0) | |
for _ in range(n): | |
wine.append(int(input())) | |
dp = [] | |
dp.append(0) | |
dp.append(wine[1]) | |
if(n>1): | |
dp.append(wine[1] + wine[2]) | |
for i in range(3,n+1): | |
dp.append(max(dp[i-1], dp[i-2] + wine[i], dp[i-3] + wine[i-1] + wine[i])) | |
print(dp[n]) |
'Coding Test > 백준' 카테고리의 다른 글
[C++/Python] 백준 11055 - 가장 큰 증가하는 부분 수열 (0) | 2020.08.04 |
---|---|
[C++/Python] 백준 11053 - 가장 긴 증가하는 부분 수열 (0) | 2020.07.31 |
[C++/Python] 백준 9465 - 스티커 (0) | 2020.07.29 |
[C++/Python] 백준 2193 - 이친수 (0) | 2020.07.28 |
[C++/Python] 백준 11057 - 오르막 수 (0) | 2020.07.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Django
- 코딩인터뷰 완전분석
- 백준
- 알고스팟
- Sqoop
- Hadoop
- HDFS
- microwaving lunch boxes
- 종만북
- 두니발 박사의 탈옥
- 스파크
- C++
- 배열과 문자열
- 완전탐색
- 팰린드롬 구하기
- 삼각형 위의 최대 경로 수 세기
- 외발 뛰기
- 분할정복
- pyspark
- 2225
- hive
- python
- 하둡
- import
- Jaeha's Safe
- 삼각형 위의 최대 경로
- 합친 lis
- 출전 순서 정하기
- HiveQL
- 하이브
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함