[백준] P1149

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

public class P1149 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), dp[][] = new int[n][3];
		for (int i = 0; i < n; i++) {
			dp[i][0] = sc.nextInt();
			dp[i][1] = sc.nextInt();
			dp[i][2] = sc.nextInt();
		}

		for (int i = n - 2; i >= 0; i--) {
			dp[i][0] += Math.min(dp[i + 1][1], dp[i + 1][2]);
			dp[i][1] += Math.min(dp[i + 1][0], dp[i + 1][2]);
			dp[i][2] += Math.min(dp[i + 1][0], dp[i + 1][1]);
		}

		System.out.println(Math.min(dp[0][0], Math.min(dp[0][1], dp[0][2])));

		sc.close();
	}
}
profile
BE Developer

0개의 댓글