• 문제 링크
https://www.acmicpc.net/problem/16439
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
static int max, n, m;
static int[][] mat;
static boolean[] visit;
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
mat = new int[n = read()][m = read()];
visit = new boolean[m];
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = read();
recur(0, new int[3]);
bw.write(String.valueOf(max));
bw.flush();
}
private static void recur(int depth, int[] arr) {
if (depth == 3) {
max = Math.max(max, sum(arr));
return;
}
for (int i = 0; i < m; i++) {
if (visit[i]) continue;
visit[i] = true;
arr[depth] = i;
recur(depth + 1, arr);
visit[i] = false;
}
}
private static int sum(int[] arr) {
int sum = 0;
for (int i = 0; i < n; i++) {
int max = 0;
for (int j : arr) max = Math.max(max, mat[i][j]);
sum += max;
}
return sum;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 24807 Math Homework - Brute Force / Java (0) | 2025.10.22 |
|---|---|
| [백준] 27494 2023년은 검은 토끼의 해 - Brute Force / Java (0) | 2025.10.21 |
| [백준] 32401 ANA는 회문이야 - Brute Force / Java (0) | 2025.10.19 |
| [백준] 5883 아이폰 9S - Brute Force / Java (0) | 2025.10.18 |
| [백준] 30216 Increasing Sublist - Brute Force / Java (0) | 2025.10.18 |
댓글