-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_1149
More file actions
36 lines (27 loc) ยท 1.07 KB
/
BAEKJOON_1149
File metadata and controls
36 lines (27 loc) ยท 1.07 KB
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
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int[][] house = new int[N+1][3];
int[][] D = new int[N+1][3];
StringTokenizer st;
for (int i = 1; i < N+1; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < 3; j++) {
house[i][j] = Integer.parseInt(st.nextToken());
}
}
for (int i = 1; i <= N; i++) {
D[i][0] = Math.min(D[i - 1][1], D[i - 1][2]) + house[i][0];
D[i][1] = Math.min(D[i - 1][0], D[i - 1][2]) + house[i][1];
D[i][2] = Math.min(D[i - 1][0], D[i - 1][1]) + house[i][2];
}
bw.write(String.valueOf(Math.min(Math.min(D[N][0], D[N][1]), D[N][2])));
bw.flush();
bw.close();
}
}