-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from oxix97/main
feat : 3월 3주차 - 종찬
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ_11054 { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
static StringTokenizer st; | ||
static int N; | ||
static int[] A, dp1, dp2; | ||
|
||
public static void main(String[] args) throws IOException { | ||
input(); | ||
solv(); | ||
br.close(); | ||
} | ||
|
||
public static void solv() { | ||
int sum = 0; | ||
for (int i = 0; i < N; i++) { | ||
dp1[i] = 1; | ||
for (int j = 0; j < i; j++) { | ||
if (A[i] > A[j] && dp1[i] <= dp1[j]) { | ||
dp1[i] = dp1[j] + 1; | ||
} | ||
} | ||
} | ||
|
||
for (int i = N - 1; i >= 0; i--) { | ||
dp2[i] = 1; | ||
for (int j = N - 1; j > i; j--) { | ||
if (A[i] > A[j] && dp2[i] <= dp2[j]) { | ||
dp2[i] = dp2[j] + 1; | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
sum = Math.max(sum, dp1[i] + dp2[i]); | ||
} | ||
System.out.println(sum - 1); | ||
} | ||
|
||
private static void input() throws IOException { | ||
N = Integer.parseInt(br.readLine()); | ||
A = new int[N]; | ||
dp1 = new int[N]; | ||
dp2 = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
A[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ_15654 { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
static StringTokenizer st; | ||
static int N, M; | ||
static int[] arr; | ||
static int[] answer; | ||
static boolean[] visited; | ||
|
||
public static void main(String[] args) throws IOException { | ||
inputs(); | ||
solv(0); | ||
|
||
System.out.println(sb); | ||
br.close(); | ||
} | ||
|
||
private static void solv(int idx) { | ||
if (idx == M) { | ||
for (int i = 0; i < M; i++) { | ||
sb.append(answer[i]).append(" "); | ||
} | ||
sb.append("\n"); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
if (visited[i]) continue; | ||
visited[i] = true; | ||
answer[idx] = arr[i]; | ||
solv(idx + 1); | ||
visited[i] = false; | ||
} | ||
|
||
} | ||
|
||
private static void inputs() throws IOException { | ||
st = new StringTokenizer(br.readLine()); | ||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
arr = new int[N]; | ||
visited = new boolean[N]; | ||
answer = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
Arrays.sort(arr); | ||
} | ||
} |