Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c955fc

Browse files
issue sowon-dev#43 1932
1 parent ea70ce3 commit 7c955fc

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

β€Žsrc/backjoon/_1932.javaβ€Ž

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/1932
3+
4+
import java.io.BufferedReader;
5+
import java.io.InputStreamReader;
6+
import java.io.IOException;
7+
import java.util.StringTokenizer;
8+
9+
public class _1932 {
10+
static int[][] arr; //μ‚Όκ°ν˜•μ΄ μ €μž₯λ˜λŠ” 2차원배열
11+
static Integer[][] dp;
12+
static int N;
13+
14+
// memory 26600 runtime 260
15+
public static void main(String[] args) throws IOException {
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
N = Integer.parseInt(br.readLine());
18+
arr = new int[N][N];
19+
dp = new Integer[N][N];
20+
StringTokenizer st;
21+
for (int i = 0; i < N; i++) {
22+
st = new StringTokenizer(br.readLine(), " ");
23+
24+
for (int j = 0; j < i + 1; j++) {
25+
arr[i][j] = Integer.parseInt(st.nextToken());
26+
}
27+
}
28+
for (int i = 0; i < N; i++) {
29+
dp[N - 1][i] = arr[N - 1][i];
30+
}
31+
32+
System.out.println(func(0, 0));
33+
}
34+
static int func(int depth, int idx) {
35+
// λ§ˆμ§€λ§‰ 행일 경우 ν˜„μž¬ μœ„μΉ˜μ˜ dpκ°’ λ°˜ν™˜
36+
if(depth == N - 1)
37+
return dp[depth][idx];
38+
39+
// νƒμƒ‰ν•˜μ§€ μ•Šμ•˜λ˜ 값일 경우 λ‹€μŒ ν–‰μ˜ μ–‘μͺ½ κ°’ 비ꡐ
40+
if (dp[depth][idx] == null) {
41+
dp[depth][idx] = Math.max(func(depth + 1, idx), func(depth + 1, idx + 1)) + arr[depth][idx];
42+
}
43+
return dp[depth][idx];
44+
45+
}
46+
}
47+
/*
48+
input
49+
5
50+
7
51+
3 8
52+
8 1 0
53+
2 7 4 4
54+
4 5 2 6 5
55+
56+
output
57+
30
58+
*/

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /