티스토리 뷰

 

 

 

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
 
import java.util.Scanner;
 
public class Grape {
 
    static int count;
    static int[] drink;
    static int[] dp;
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        count = sc.nextInt();
        drink = new int[count + 1];
        dp = new int[count + 1];
 
        for (int i = 1; i < count + 1; i++) {
            drink[i] = sc.nextInt();
        }
        dp[1= drink[1];
 
        if (count >= 2)
            dp[2= drink[2+ dp[1];
        
        for (int i = 3; i < count + 1; i++) {
            // 마지막 포도주를 고를 때를 기준으로  n-1잔을 마실때와 안마실 때 2가지 경우의 수 존재
            dp[i] = Math.max(dp[i - 3+ drink[i - 1+ drink[i], dp[i - 2+ drink[i]);
            // 2번 연속 포도주 안먹기 가능
            dp[i] = Math.max(dp[i], dp[i - 1]);
        }
        System.out.println(dp[count]);
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함