Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea70ce3

Browse files
committed
issue #43 1149
1 parent 5f567cc commit ea70ce3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

โ€Žsrc/backjoon/_1149.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/1149
3+
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.util.StringTokenizer;
8+
9+
public class _1149 {
10+
final static int Red = 0;
11+
final static int Green = 1;
12+
final static int Blue = 2;
13+
14+
static int[][] Cost;
15+
16+
public static void main(String[] args) throws IOException {
17+
// memory 12036 runtime 92
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
int N = Integer.parseInt(br.readLine());
20+
21+
Cost = new int[N][3];
22+
23+
StringTokenizer st;
24+
for(int i = 0; i < N; i++) {
25+
26+
st = new StringTokenizer(br.readLine(), " ");
27+
28+
Cost[i][Red] = Integer.parseInt(st.nextToken());
29+
Cost[i][Green] = Integer.parseInt(st.nextToken());
30+
Cost[i][Blue] = Integer.parseInt(st.nextToken());
31+
}
32+
33+
// ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ ์ค‘ ์ตœ์†Ÿ๊ฐ’์„ ๋”ํ•˜๊ธฐ
34+
for (int i = 1; i < N; i++) {
35+
Cost[i][Red] += Math.min(Cost[i - 1][Green], Cost[i - 1][Blue]);
36+
Cost[i][Green] += Math.min(Cost[i - 1][Red], Cost[i - 1][Blue]);
37+
Cost[i][Blue] += Math.min(Cost[i - 1][Red], Cost[i - 1][Green]);
38+
}
39+
40+
System.out.println(Math.min(Math.min(Cost[N - 1][Red], Cost[N - 1][Green]), Cost[N - 1][Blue]));
41+
}
42+
}
43+
/*
44+
input
45+
3
46+
26 40 83
47+
49 60 57
48+
13 89 99
49+
50+
output
51+
96
52+
*/

0 commit comments

Comments
ย (0)