[백준] P1932

동민·2021년 3월 11일
0
import java.util.ArrayList;
import java.util.Scanner;

public class P1932 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for (int i = 1; i <= n; i++) {
			ArrayList<Integer> temp = new ArrayList<>();
			for (int j = 0; j < i; j++) {
				temp.add(sc.nextInt());
			}
			list.add(temp);
		}

		for (int i = n - 2; i >= 0; i--) {
			for (int j = 0; j < list.get(i).size(); j++) {
				list.get(i).set(j, list.get(i).get(j) + Math.max(list.get(i + 1).get(j), list.get(i + 1).get(j + 1)));
			}
		}

		System.out.println(list.get(0).get(0));
		sc.close();
	}
}
profile
BE Developer

0개의 댓글