Skip to content

Commit 54315e5

Browse files
committed
[DP] baekjoon-11054
1 parent d1b9844 commit 54315e5

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

โ€ŽREADME.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
| 21 | | [Baekjoon-14002 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 4](src/DP/P14002) | |
214214
| 22 | | [Baekjoon-11055 ๊ฐ€์žฅ ํฐ ์ฆ๊ฐ€ ๋ถ€๋ถ„ ์ˆ˜์—ด](src/DP/P11055) | |
215215
| 23 | | [Baekjoon-11722 ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด](src/DP/P11722) | |
216+
| 24 | | [Baekjoon-11054 ๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด](src/DP/P11054) | |
216217

217218
---
218219

โ€Žsrc/DP/P11054/Main.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package DP.P11054;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static int N;
9+
static int[] A;
10+
static int[] inc, dec;
11+
12+
public static void main(String[] args) throws Exception {
13+
System.setIn(new FileInputStream("src/DP/P11054/input.txt"));
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
16+
N = Integer.parseInt(br.readLine());
17+
18+
A = new int[N];
19+
StringTokenizer st = new StringTokenizer(br.readLine());
20+
for (int i = 0; i < N; i++)
21+
A[i] = Integer.parseInt(st.nextToken());
22+
23+
inc = new int[N];
24+
dec = new int[N];
25+
for (int i = 0; i < N; i++) {
26+
int max_inc = 0;
27+
for (int j = 0; j < i; j++) {
28+
if (A[j] < A[i]) {
29+
max_inc = Math.max(max_inc, inc[j]);
30+
}
31+
}
32+
inc[i] = max_inc + 1;
33+
}
34+
for (int i = N-1; i >= 0; i--) {
35+
int max_dec = 0;
36+
for (int j = N-1; j > i; j--) {
37+
if (A[j] < A[i]) {
38+
max_dec = Math.max(max_dec, dec[j]);
39+
}
40+
}
41+
dec[i] = max_dec + 1;
42+
}
43+
44+
int ans = 0;
45+
for (int i = 0; i < N; i++) {
46+
ans = Math.max(ans, inc[i] + dec[i] - 1);
47+
}
48+
49+
System.out.println(ans);
50+
}
51+
}

โ€Žsrc/DP/P11054/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## [baekjoon-11054] ๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด
2+
3+
![image](https://user-images.githubusercontent.com/22045163/100743086-2091f900-341f-11eb-844e-783e419d8d57.png)
4+
5+
์ด๋ฒˆ ๋ฌธ์ œ๋„ ํ’€์ด ๊ณผ์ • ์—†์ด ๋จธ๋ฆฟ์†์œผ๋กœ ์ƒ๊ฐํ•ด์„œ ํ’€์—ˆ๋‹ค !!
6+
7+
๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ **์•ž์—์„œ๋ถ€ํ„ฐ** ๊ตฌํ•ด์„œ ์ €์žฅํ•˜๊ณ ,
8+
๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ **๋’ค์—์„œ๋ถ€ํ„ฐ** ๊ตฌํ•ด์„œ ์ €์žฅํ•˜์—ฌ
9+
๋‘ ๊ฐ€์ง€ ๋ฐฐ์—ด์— ๋Œ€ํ•˜์—ฌ ๊ฐ ์ธ๋ฑ์Šค์— ์ €์žฅ๋œ ๊ฐ’์˜ ํ•ฉ์—์„œ 1(์ž๊ธฐ ์ž์‹  ์ค‘๋ณต)์„ ๋นผ๋ฉด
10+
๊ฐ ์ธ๋ฑ์Šค๋ณ„๋กœ ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด ๊ธธ์ด๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

โ€Žsrc/DP/P11054/input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
1 5 2 1 4 3 4 5 2 1

0 commit comments

Comments
ย (0)