Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 프로그래머스 도둑질 java
- 코딩테스트
- mysql
- time complexity
- 백준 15661
- 알고리즘
- 백준 16927
- 백준 17425
- 프로그래머스 숫자의 표현 java
- 백준 18290
- java 올림
- 백준 16935
- 프로그래머스 옹알이 java
- 프로그래머스 네트워크 java
- 백준 11723
- 네트워크
- Arrays
- 프로그래머스 연속된 수의 합 java
- 백준 14391
- Codility
- 0으로 채우기
- Algorithm
- 백준 4375
- java
- Math.floor()
- java 반올림
- java 내림
- Math.ceil()
- 자바
- sort
Archives
- Today
- Total
취미처럼
[백준] 11054번 가장 긴 바이토닉 부분 수열 본문
https://www.acmicpc.net/problem/11054
11054번: 가장 긴 바이토닉 부분 수열
첫째 줄에 수열 A의 크기 N이 주어지고, 둘째 줄에는 수열 A를 이루고 있는 Ai가 주어진다. (1 ≤ N ≤ 1,000, 1 ≤ Ai ≤ 1,000)
www.acmicpc.net
왼쪽부터 증가하는 수열 길이의 최대값 + 오른쪽부터 증가하는 수열 길이의 최대값
플러스 했으므로 중복이라 -1 해주면 됨
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] arr = new int[n+1];
int[] dpLeft = new int[n+1];
int[] dpRight = new int[n+1];
for(int i=1; i<=n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
dpLeft[1] = 1;
dpRight[n] = 1;
for(int i =2; i<=n; i++) {
dpLeft[i] = 1;
for(int j = 1; j < i; j++) {
if(arr[i] > arr[j]) {
dpLeft[i] = Math.max(dpLeft[i], dpLeft[j] + 1);
}
}
}
for(int i=n-1; i >=0; i--) {
dpRight[i] = 1;
for(int j = n; j > i ; j--) {
if(arr[i] > arr[j]) {
dpRight[i] = Math.max(dpRight[i], dpRight[j] + 1);
}
}
}
int max = 0;
for(int i = 0; i <= n; i++) {
max = Math.max(max, dpLeft[i] + dpRight[i]);
}
System.out.println(max - 1);
}
}'Algorithm > 백준' 카테고리의 다른 글
| [백준] 2133번 타일 채우기 (0) | 2021.03.09 |
|---|---|
| [백준] 13398번 연속합2 (0) | 2021.03.09 |
| [백준] 11722번 가장 긴 감소하는 부분 수열 (0) | 2021.03.09 |
| [백준] 11055번 가장 큰 증가 부분 수열 (0) | 2021.03.09 |
| [백준] 1932번 정수 삼각형 (0) | 2021.03.08 |
Comments