Skip to content

Commit

Permalink
백준/단계별: 1932 정수 삼각형 문제풀이 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunnnn committed Oct 25, 2023
1 parent 4a9caed commit 6571178
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/baekjoon/step/dynamicProgramming/PROB1932.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package baekjoon.step.dynamicProgramming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class PROB1932 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static int[][] dp;
static int[][] numbers;
static int N;

public static void main(String[] args) throws IOException {
N = Integer.parseInt(br.readLine());
numbers = new int[N][N];
dp = new int[N][N];

for (int i = 0; i < N; i ++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < i + 1; j++) {
numbers[i][j] = Integer.parseInt(st.nextToken());
}
}

solve();
}

public static void solve() {
dp[0][0] = numbers[0][0];

for (int i = 1; i < dp.length; i ++) {
for (int j = 0; j < i + 1; j ++) {
if (j == 0){
dp[i][0] = dp[i - 1][0] + numbers[i][0];
} else {
dp[i][j] = Math.max(dp[i - 1][j - 1], dp[i - 1][j]) + numbers[i][j];
}
}
}

Arrays.sort(dp[dp.length - 1]);
System.out.println(dp[dp.length - 1][dp.length - 1]);
}
}

0 comments on commit 6571178

Please sign in to comment.