FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-for-coding-test/16/2.java at master · ndb796/python-for-coding-test · GitHub
ndb796
/
python-for-coding-test
Public
Notifications
You must be signed in to change notification settings
Fork
830
Star
2.4k
Code
Issues
129
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-for-coding-test
/
16
/
2.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (33 loc) · 1.17 KB
Breadcrumbs
python-for-coding-test
/
16
/
2.java
Copy path
File metadata and controls
36 lines (33 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import
java
.
util
.*;
public
class
Main
{
static
int
n
;
static
int
[][]
dp
=
new
int
[
500
][
500
];
// 다이나믹 프로그래밍을 위한 DP 테이블 초기화
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
n
=
sc
.
nextInt
();
for
(
int
i
=
0
;
i
<
n
;
i
++) {
for
(
int
j
=
0
;
j
<
i
+
1
;
j
++) {
dp
[
i
][
j
] =
sc
.
nextInt
();
}
}
// 다이나믹 프로그래밍으로 2번째 줄부터 내려가면서 확인
for
(
int
i
=
1
;
i
<
n
;
i
++) {
for
(
int
j
=
0
;
j
<=
i
;
j
++) {
int
upLeft
,
up
;
// 왼쪽 위에서 내려오는 경우
if
(
j
==
0
)
upLeft
=
0
;
else
upLeft
=
dp
[
i
-
1
][
j
-
1
];
// 바로 위에서 내려오는 경우
if
(
j
==
i
)
up
=
0
;
else
up
=
dp
[
i
-
1
][
j
];
// 최대 합을 저장
dp
[
i
][
j
] =
dp
[
i
][
j
] +
Math
.
max
(
upLeft
,
up
);
}
}
int
result
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++) {
result
=
Math
.
max
(
result
,
dp
[
n
-
1
][
i
]);
}
System
.
out
.
println
(
result
);
}
}
Back
|
FazBrowse Home
|
New Git URL