diff --git "a/lkhyun/202506/29 BOJ G4 RGB\352\261\260\353\246\254 2.md" "b/lkhyun/202506/29 BOJ G4 RGB\352\261\260\353\246\254 2.md" new file mode 100644 index 00000000..31615199 --- /dev/null +++ "b/lkhyun/202506/29 BOJ G4 RGB\352\261\260\353\246\254 2.md" @@ -0,0 +1,45 @@ +```java +import java.util.*; +import java.io.*; +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int[][] cost; + static int[][] dp; + + public static void main(String[] args) throws Exception{ + N = Integer.parseInt(br.readLine()); + cost = new int[N+1][3]; + + for(int i=1; i<=N;i++){ + st = new StringTokenizer(br.readLine()); + cost[i][0] = Integer.parseInt(st.nextToken()); + cost[i][1] = Integer.parseInt(st.nextToken()); + cost[i][2] = Integer.parseInt(st.nextToken()); + } + + int min = Integer.MAX_VALUE; + for(int firstColor=0; firstColor<3; firstColor++){ + dp = new int[N+1][3]; + dp[1][firstColor] = cost[1][firstColor]; + dp[1][(firstColor+1)%3] = 10000000; + dp[1][(firstColor+2)%3] = 10000000; + + for(int i=2;i