File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ https://www.acmicpc.net/problem/2156
3+ # 문제 : 최대한 많은 양의 포도주 섭취
4+ <조건>
5+ 1. 선택한 잔의 포두주는 모두 섭취 ,마신 뒤 원상복귀
6+ 2. 연속으로 놓여진 3잔 모두 섭취 불가
7+
8+ # 최대문제 -> "DP"
9+
10+ 점화식
11+ dp[i] : 현재 i 에서 최대 마실 수 있는 포도주 총합
12+ 1. 현재 O , 이전 O , 전전 x :
13+ 2. 현재 , 이전 x , 전전 O =
14+ 3. 현재 x , 이전 o , 전전 o =
15+ dp[i] = max(cups[i] + cups[i-1] + dp[i-3] , cups[i] + dp[i-2] , dp[i-1])
16+ """
17+ # 1. 입력변수
18+ N = int (input ())
19+ cups = [int (input ()) for _ in range (N )]
20+
21+ # 2.
22+ dp = [0 ]* N
23+
24+ dp [0 ] = cups [0 ]
25+ if N >= 2 :
26+ dp [1 ] = sum (cups [0 :2 ])
27+ if N >= 3 :
28+ dp [2 ] = max (cups [2 ] + cups [1 ] , cups [2 ] + cups [0 ] , dp [1 ])
29+ if N >= 4 :
30+ for i in range (3 ,N ):
31+ dp [i ] = max (cups [i ] + cups [i - 1 ] + dp [i - 3 ] , cups [i ] + dp [i - 2 ] , dp [i - 1 ])
32+ # print(dp)
33+ print (dp [- 1 ])
You can’t perform that action at this time.
0 commit comments