• 문제 링크
14767번: Flow Shop
There is only one test case in each file. It begins with a single line containing N and M (1 ≤ N, M ≤ 1000), the number of swathers and stages (respectively). Following this are N lines, each with M integers. The j’th integer of the i’th line is Pi
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int n = read(), m = read();
int[][] cache = new int[n + 1][m + 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cache[i][j] = read();
for (int i = 1; i <= n; sb.append(cache[i++][m]).append(" "))
for (int j = 1; j <= m; j++) cache[i][j] += Math.max(cache[i - 1][j], cache[i][j - 1]);
bw.write(sb.toString());
bw.flush();
}
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' 카테고리의 다른 글
[백준] 18295 Ants - Brute Force / Java (0) | 2024.02.22 |
---|---|
[백준] 29994 Investigating Zeroes and Ones - Dynamic Programming / Java (0) | 2024.02.21 |
[백준] 7515 Prehistoric Operating Systems - Dynamic Programming / Java (0) | 2024.02.19 |
[백준] 26948 Plankan - Dynamic Programming / Java (0) | 2024.02.18 |
[백준] 8582 Park - Dynamic Programming / Java (0) | 2024.02.17 |
댓글