본문 바로가기
알고리즘 & 자료구조/백준

백준 11052

by 신재권 2021. 8. 22.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main11052 {
	
	public static int[] d;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine()); //카드개수 N개
		int[] P = new int[N+1]; //가격 
		d = new int[N+1]; //메모리제이션 
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		for(int i=1; i<=N; i++){
			P[i] = Integer.parseInt(st.nextToken());
		}
		
		//점화식 : D[N] = max(D[N], D[N-i]+P[i])
		for(int i=1; i<=N; i++){
			for(int j=1; j<=i; j++){
				d[i] = Math.max(d[i], d[i-j] + P[j]);
			}
		}
		System.out.println(d[N]);
	}

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 15990  (0) 2021.08.23
백준 16194  (0) 2021.08.23
백준 9095  (0) 2021.08.22
백준 11727  (0) 2021.08.21
백준 11726  (0) 2021.08.21