본문으로 바로가기
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

백준알고리즘


https://www.acmicpc.net/problem/1149


설명은 여기..http://spillmoon.tistory.com/176


import java.util.Scanner; public class Main { public static void main(String args[]) throws Exception { Scanner scan = new Scanner(System.in); int homeCount = Integer.parseInt(scan.nextLine().trim()); int inputArray[][] = new int[homeCount][3]; int memoArray[][] = new int[homeCount][3]; for(int i=0; i < homeCount; i++) { inputArray[i][0] = scan.nextInt(); inputArray[i][1] = scan.nextInt(); inputArray[i][2] = Integer.parseInt(scan.nextLine().trim()); } memoArray[0][0] = inputArray[0][0]; memoArray[0][1] = inputArray[0][1]; memoArray[0][2] = inputArray[0][2]; for(int i=1; i < homeCount; i++) { memoArray[i][0] = inputArray[i][0] + Math.min(memoArray[i-1][1], memoArray[i-1][2]); memoArray[i][1] = inputArray[i][1] + Math.min(memoArray[i-1][0], memoArray[i-1][2]); memoArray[i][2] = inputArray[i][2] + Math.min(memoArray[i-1][0], memoArray[i-1][1]); } System.out.println(Math.min(memoArray[homeCount-1][0], Math.min(memoArray[homeCount-1][1], memoArray[homeCount-1][2]))); scan.close(); } }